image_output_1.png
import numpy as np

import pandas as pd

import numpy as np
import pandas as pd
import lightgbm as lgb
import graphviz as graphviz
import shap
train = pd.read_csv('../input/titanic/train.csv')
train['FamilyMembers'] = train['SibSp'] + train['Parch']
train['Female'] = train['Sex'].map({'male': 0, 'female': 1}).astype(np.int8)
train['Pclass_cat'] = (train['Pclass'] - 1).astype(np.int8)
train['Adult'] = (train['Age'] > 16).astype(np.int8)
train['Adult'].values[train['Age'].isna()] = 1
train['Age'] = train.groupby(['Pclass', 'Female'])['Age'].transform(lambda x: x.fillna(x.median()))

new_data = pd.DataFrame({'Person': ['Rose', 'Jack'], 'Pclass': [1, 3], 'Age': [17, 20], 'FamilyMembers': [1, 0], 'Female': [1, 0]})
new_data