Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
<SOS> metric: MAE Kaggle data source: pubg-finish-placement-prediction-(kernels-only)<normalization>
def get_sample(df,n):

 idxs = sorted(np.random.permutation(len(df)) [:n])
 return df.iloc[idxs].copy()
def proc_df(df, y_fld, skip_flds=None, do_scale=False, na_dict=None,
preproc_fn=None, max_n_cat=None, subset=None, mapper=None):

 if not skip_flds: skip_flds=[]
if subset: df = get_sample(df,subset)
 df = df.copy()
if preproc_fn: preproc_fn(df)
 y = df[y_fld].values
df.drop(skip_flds+[y_fld], axis=1, inplace=True)
 if na_dict is None: na_dict = {}
for n,c in df.items() : na_dict = fix_missing(df, c, n, na_dict)
 if do_scale: mapper = scale_vars(df, mapper)
 for n,c in df.items() : numericalize(df, c, n, max_n_cat)
 res = [pd.get_dummies(df, dummy_na=True), y, na_dict]
if do_scale: res = res + [mapper]
return res
def rf_feat_importance(m, df):
return pd.DataFrame({'cols':df.columns, 'imp':m.feature_importances_}
).sort_values('imp', ascending=False)
 def set_rf_samples(n):

 forest._generate_sample_indices =(lambda rs, n_samples:
forest.check_random_state(rs ).randint(0, n_samples, n))
def reset_rf_samples() :

 forest._generate_sample_indices =(lambda rs, n_samples:
forest.check_random_state(rs ).randint(0, n_samples, n_samples))
def scale_fare() :
global combined
combined['Fare'] = boxcox1p(combined['Fare'],
boxcox_normmax(combined['Fare'] + 1))
status('NFareBin')
 return combined<categorify>
%load_ext autoreload
%autoreload 2
%matplotlib inline
mpl.rc('axes', labelsize=14)
 mpl.rc('xtick', labelsize=12)
 mpl.rc('ytick', labelsize=12)
def process_embarked() :
global combined
combined.Embarked.fillna(combined.Embarked.mode() [0], inplace=True)
 embarked_dummies = pd.get_dummies(combined['Embarked'], prefix='Embarked')
 combined = pd.concat([combined, embarked_dummies], axis=1)
 combined.drop('Embarked', axis=1, inplace=True)
 status('Embarked')
 return combined<categorify>
train = pd.read_csv(".. /input/pubg-finish-placement-prediction/train_V2.csv")
 test = pd.read_csv(".. /input/pubg-finish-placement-prediction/test_V2.csv" )
def process_cabin() :
global combined
combined['Cabin_Informed'] = [
1 if pd.notnull(cab)else 0 for cab in combined['Cabin']
]
combined.Cabin.fillna('M', inplace=True)
 combined['Deck'] = combined['Cabin'].map(lambda c: c[0])
 combined['Deck'].replace('T', 'A', inplace=True)
 cabin_dummies = pd.get_dummies(combined['Deck'], prefix='Deck')
 combined = pd.concat([combined, cabin_dummies], axis=1)
 combined.drop('Cabin', axis=1, inplace=True)
 combined.drop('Deck', axis=1, inplace=True)
 status('Cabin')
 return combined<categorify>
train[train['winPlacePerc'].isnull() ]
def process_sex() :
global combined
combined['Sex'] = combined['Sex'].map({'male': 1, 'female': 0})
 status('Sex')
 return combined<categorify>
train.drop(2744604, inplace=True )
def process_pclass() :
global combined
pclass_dummies = pd.get_dummies(combined['Pclass'], prefix='Pclass')
 combined = pd.concat([combined, pclass_dummies], axis=1)
 combined.drop('Pclass', axis=1, inplace=True)
 status('Pclass')
 return combined<feature_engineering>
train[train['winPlacePerc'].isnull() ]
def process_ticket() :
global combined

 def cleanTicket(ticket):
ticket = ticket.replace('.', '')
 ticket = ticket.replace('/', '')
 ticket = ticket.split()
ticket = map(lambda t: t.strip() , ticket)
 ticket = list(filter(lambda t: not t.isdigit() , ticket))
if len(ticket)> 0:
return ticket[0]
else:
return 'Unknown'
combined['Ticket'] = combined['Ticket'].map(cleanTicket)
 tickets_dummies = pd.get_dummies(combined['Ticket'], prefix='Ticket')
 combined = pd.concat([combined, tickets_dummies], axis=1)
 combined.drop('Ticket', inplace=True, axis=1)
 status('Ticket')
 return combined<drop_column>
train['totalDistance'] = train['walkDistance'] + train['rideDistance'] + train['swimDistance']
train['healsAndBoosts'] = train['heals']+train['boosts']
def dropper() :
global combined
combined.drop('Cabin', axis=1, inplace=True)
 combined.drop('PassengerId', inplace=True, axis=1)
 combined.drop('Last_Name', inplace=True, axis=1)
 combined.drop('Survived', inplace=True, axis=1)
 combined.drop('Ticket', inplace=True, axis=1)
 return combined<categorify>
train['team'] = [1 if i>50 else 2 if(i>25 & i<=50)else 4 for i in train['numGroups']]
train['playersJoined'] = train.groupby('matchId')['matchId'].transform('count' )
combined = get_combined_data()
combined = family_survival()
combined = process_family()
combined = get_titles()
combined = process_names()
combined = process_age()
combined = age_binner()
combined = process_fares()
combined = process_fare_bin(onehot='no')
 combined = process_embarked()
combined = process_sex()
combined = dropper()
print(
 f'Processed everything.Missing values left: {combined.isna().sum().sum() }'
)<prepare_output>
train['killsNorm'] = train['kills']*(( 100-train['playersJoined'])/100 + 1)
 train['damageDealtNorm'] = train['damageDealt']*(( 100-train['playersJoined'])/100 + 1)
 train['maxPlaceNorm'] = train['maxPlace']*(( 100-train['playersJoined'])/100 + 1)
 train['matchDurationNorm'] = train['matchDuration']*(( 100-train['playersJoined'])/100 + 1)
 to_show = ['Id', 'kills','killsNorm','damageDealt', 'damageDealtNorm', 'maxPlace', 'maxPlaceNorm', 'matchDuration', 'matchDurationNorm']
train[to_show][0:11]
v_merged = combined.copy()
v_merged['Survived'] = v_train['Survived']
v_merged.head()<import_modules>
train['headshot_rate'] = train['headshotKills'] / train['kills']
train['headshot_rate'] = train['headshot_rate'].fillna(0 )
from sklearn.ensemble import GradientBoostingClassifier, RandomForestClassifier
from sklearn.model_selection import StratifiedKFold, cross_val_score, learning_curve, cross_validate, train_test_split, KFold
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, roc_auc_score, roc_curve, plot_roc_curve, auc
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.neural_network import MLPClassifier
from sklearn.decomposition import PCA
from sklearn.pipeline import Pipeline, make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.feature_selection import RFE
import xgboost as xgb
import lightgbm as lgb
from mlxtend.plotting import plot_decision_regions<load_from_csv>
train['killsWithoutMoving'] =(( train['kills'] > 0)&(train['totalDistance'] == 0))
train.drop(train[train['killsWithoutMoving'] == True].index, inplace=True )
def recover_train_test_target() :
global combined
y = pd.read_csv('/kaggle/input/titanic/train.csv', usecols=['Survived'])['Survived']
X = combined.iloc[:idx]
X_test = combined.iloc[idx:]
return X, X_test, y
X, X_test, y = recover_train_test_target()<choose_model_class>
train[train['roadKills'] > 10]
cv = StratifiedKFold(10, shuffle=True, random_state=42)
 rf = RandomForestClassifier(criterion='gini',
n_estimators=1750,
max_depth=7,
min_samples_split=6,
min_samples_leaf=6,
max_features='auto',
oob_score=True,
random_state=42,
n_jobs=-1,
verbose=0)
 lg = lgb.LGBMClassifier(max_bin=4,
num_iterations=550,
learning_rate=0.0114,
max_depth=3,
num_leaves=7,
colsample_bytree=0.35,
random_state=42,
n_jobs=-1)
 xg = xgb.XGBClassifier(
 n_estimators=2800,
min_child_weight=0.1,
learning_rate=0.002,
max_depth=2,
subsample=0.47,
colsample_bytree=0.35,
gamma=0.4,
reg_lambda=0.4,
random_state=42,
n_jobs=-1, 
)
 sv = SVC(probability=True)
 logreg = LogisticRegression(n_jobs=-1, solver='newton-cg')
 gb = GradientBoostingClassifier(random_state=42)
 gnb = GaussianNB()
mlp = MLPClassifier(random_state=42 )<define_variables>
train.drop(train[train['roadKills'] > 10].index, inplace=True)
estimators = [rf, lg, xg, gb, sv, logreg, gnb, mlp]<compute_train_metric>
train.drop(train[train['kills'] > 30].index, inplace=True )
def model_check(X, y, estimators, cv):
model_table = pd.DataFrame()
row_index = 0
for est in estimators:
MLA_name = est.__class__.__name__
model_table.loc[row_index, 'Model Name'] = MLA_name
cv_results = cross_validate(
 est,
X,
y,
cv=cv,
scoring='accuracy',
return_train_score=True,
n_jobs=-1 
)
 model_table.loc[row_index, 'Train Accuracy Mean'] = cv_results[
'train_score'].mean()
model_table.loc[row_index, 'Test Accuracy Mean'] = cv_results[
'test_score'].mean()
model_table.loc[row_index, 'Test Std'] = cv_results['test_score'].std()
model_table.loc[row_index, 'Time'] = cv_results['fit_time'].mean()
row_index += 1
model_table.sort_values(by=['Test Accuracy Mean'],
ascending=False,
inplace=True)
 return model_table<compute_train_metric>
train.drop(train[train['longestKill'] >= 1000].index, inplace=True )
raw_models = model_check(X, y, estimators, cv)
 display(raw_models.style.background_gradient(cmap='summer_r'))<train_on_grid>
train.drop(train[train['walkDistance'] >= 10000].index, inplace=True )
def m_roc(estimators, cv, X, y):
fig, axes = plt.subplots(math.ceil(len(estimators)/ 2),
2,
figsize=(25, 50))
axes = axes.flatten()
for ax, estimator in zip(axes, estimators):
tprs = []
aucs = []
mean_fpr = np.linspace(0, 1, 100)
 for i,(train, test)in enumerate(cv.split(X, y)) :
estimator.fit(X.loc[train], y.loc[train])
 viz = plot_roc_curve(estimator,
X.loc[test],
y.loc[test],
name='ROC fold {}'.format(i),
alpha=0.3,
lw=1,
ax=ax)
 interp_tpr = interp(mean_fpr, viz.fpr, viz.tpr)
 interp_tpr[0] = 0.0
tprs.append(interp_tpr)
 aucs.append(viz.roc_auc)
 ax.plot([0, 1], [0, 1],
linestyle='--',
lw=2,
color='r',
label='Chance',
alpha=.8)
 mean_tpr = np.mean(tprs, axis=0)
 mean_tpr[-1] = 1.0
mean_auc = auc(mean_fpr, mean_tpr)
 std_auc = np.std(aucs)
 ax.plot(mean_fpr,
mean_tpr,
color='b',
label=r'Mean ROC(AUC = %0.2f $\pm$ %0.2f)' % 
(mean_auc, std_auc),
lw=2,
alpha=.8)
 std_tpr = np.std(tprs, axis=0)
 tprs_upper = np.minimum(mean_tpr + std_tpr, 1)
 tprs_lower = np.maximum(mean_tpr - std_tpr, 0)
 ax.fill_between(mean_fpr,
tprs_lower,
tprs_upper,
color='grey',
alpha=.2,
label=r'$\pm$ 1 std.dev.')
 ax.set(xlim=[-0.02, 1.02],
ylim=[-0.02, 1.02],
title=f'{estimator.__class__.__name__} ROC')
 ax.legend(loc='lower right', prop={'size': 18})
 plt.show()<compute_test_metric>
train.drop(train[train['rideDistance'] >= 20000].index, inplace=True )
m_roc(estimators, cv, X, y )<compute_test_metric>
train[train['swimDistance'] >= 2000]
f_imp(estimators, X, y, 14 )<train_model>
train.drop(train[train['swimDistance'] >= 2000].index, inplace=True )
rf.fit(X, y)
 estimator = rf.estimators_[0]
export_graphviz(estimator, out_file='tree.dot',
feature_names = X.columns,
class_names = ['Not Survived','Survived'],
rounded = True, proportion = False,
precision = 2, filled = True)
 call(['dot', '-Tpng', 'tree.dot', '-o', 'tree.png', '-Gdpi=600'])
 plt.figure(figsize =(40, 20))
plt.imshow(plt.imread('tree.png'))
plt.axis('off');
plt.show() ;<split>
train.drop(train[train['weaponsAcquired'] >= 80].index, inplace=True )
def f_selector(X, y, est, features):
X_train, X_valid, y_train, y_valid = train_test_split(X,
y,
test_size=0.4,
random_state=42)
 rfe = RFE(estimator=est, n_features_to_select=features, verbose=1)
 rfe.fit(X_train, y_train)
 print(dict(zip(X.columns, rfe.ranking_)))
 print(X.columns[rfe.support_])
 acc = accuracy_score(y_valid, rfe.predict(X_valid))
print("{0:.1%} accuracy on test set.".format(acc))
X_red = X[X_train.columns[rfe.support_].to_list() ]
X_te_red = X_test[X_train.columns[rfe.support_].to_list() ]
return X_red, X_te_red<compute_test_metric>
train.drop(train[train['heals'] >= 40].index, inplace=True )
X_sel, X_test_sel = f_selector(X, y, rf, 11 )<normalization>
print('There are {} different Match types in the dataset.'.format(train['matchType'].nunique()))
pipe = Pipeline([ 
('scaler', StandardScaler()), 
('reducer', PCA(n_components=2)) ,
])
 X_sel_red = pipe.fit_transform(X_sel)
 X_test_sel_red = pipe.transform(X_test_sel )<split>
train = pd.get_dummies(train, columns=['matchType'])
 matchType_encoding = train.filter(regex='matchType')
 matchType_encoding.head()
def prob_reg(X, y):
figure = plt.figure(figsize=(20, 40))
h =.02
i = 1
X_train, X_test, y_train, y_test = \
train_test_split(X, y, test_size=.4, random_state=42)
 x_min, x_max = X_sel_red[:, 0].min() -.5, X_sel_red[:, 0].max() +.5
y_min, y_max = X_sel_red[:, 1].min() -.5, X_sel_red[:, 1].max() +.5
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
cm = plt.cm.RdYlGn
cm_bright = ListedColormap(['
ax = plt.subplot(5, 2, i)
 for clf in estimators:
ax = plt.subplot(math.ceil(len(estimators)/ 2), 2, i)
 clf.fit(X_train, y_train)
 score = clf.score(X_test, y_test)
 if hasattr(clf, "decision_function"):
Z = clf.decision_function(np.c_[xx.ravel() , yy.ravel() ])
 else:
Z = clf.predict_proba(np.c_[xx.ravel() , yy.ravel() ])[:, 1]
Z = Z.reshape(xx.shape)
 ax.contourf(xx, yy, Z, cmap=cm, alpha=.8)
 g = ax.scatter(X_train[:, 0],
X_train[:, 1],
c=y_train,
cmap=cm_bright,
edgecolors='k')
 ax.scatter(X_test[:, 0],
X_test[:, 1],
c=y_test,
cmap=cm_bright,
edgecolors='k',
alpha=0.6)
 ax.set_xlim(xx.min() , xx.max())
 ax.set_ylim(yy.min() , yy.max())
 ax.set_title(clf.__class__.__name__)
 ax.set_xlabel('PCA 1')
 ax.set_ylabel('PCA 2')
 plt.legend(handles=g.legend_elements() [0],
labels=['Not Survived', 'Survived'],
framealpha=0.3,
scatterpoints=1)
 i += 1
plt.tight_layout()
plt.show()<compute_test_metric>
train['groupId'] = train['groupId'].astype('category')
 train['matchId'] = train['matchId'].astype('category')
 train['groupId_cat'] = train['groupId'].cat.codes
train['matchId_cat'] = train['matchId'].cat.codes
train.drop(columns=['groupId', 'matchId'], inplace=True)
 train[['groupId_cat', 'matchId_cat']].head()
dec_regs(X_sel_red, y, estimators )<compute_test_metric>
train.drop(columns = ['Id'], inplace=True )
prob_reg(X_sel_red, y )<compute_train_metric>
test['totalDistance'] = test['rideDistance'] + test['walkDistance'] + test['swimDistance']
test['healsAndBoosts'] = test['heals'] + test['boosts']
test['team'] = [1 if i>50 else 2 if(i>25 & i<=50)else 4 for i in test['numGroups']]
test['playersJoined'] = test.groupby('matchId')['matchId'].transform('count')
 test['killsNorm'] = test['kills']*(( 100-test['playersJoined'])/100 + 1)
 test['damageDealtNorm'] = test['damageDealt']*(( 100-test['playersJoined'])/100 + 1)
 test['maxPlaceNorm'] = test['maxPlace']*(( 100-train['playersJoined'])/100 + 1)
 test['matchDurationNorm'] = test['matchDuration']*(( 100-test['playersJoined'])/100 + 1)
 test['headshot_rate'] = test['headshotKills'] / test['kills']
test['headshot_rate'] = test['headshot_rate'].fillna(0)
 test['killsWithoutMoving'] =(( test['kills'] > 0)&(test['totalDistance'] == 0))
test = pd.get_dummies(test, columns=['matchType'])
 test['groupId'] = test['groupId'].astype('category')
 test['matchId'] = test['matchId'].astype('category')
 test['groupId_cat'] = test['groupId'].cat.codes
test['matchId_cat'] = test['matchId'].cat.codes
test.drop(columns=['groupId', 'matchId'], inplace=True )
pca_models = model_check(X_sel_red, y, estimators, cv)
 display(pca_models.style.background_gradient(cmap='summer_r'))<train_model>
X = train_sample.drop(columns=['winPlacePerc'])
 y = train_sample['winPlacePerc']
rand_model_full_data = rf.fit(X, y)
 print(accuracy_score(y, rand_model_full_data.predict(X)))
 y_pred = rand_model_full_data.predict(X_test )<save_to_csv>
def split_vals(a, n : int):
return a[:n].copy() , a[n:].copy()
val_perc = 0.12
n_valid = int(val_perc * sample)
 n_trn = len(X)- n_valid
raw_train, raw_valid = split_vals(train_sample, n_trn)
 X_train, X_valid = split_vals(X, n_trn)
 y_train, y_valid = split_vals(y, n_trn)
 print('Sample train shape: ', X_train.shape,
'Sample target shape: ', y_train.shape,
'Sample validation shape: ', X_valid.shape )
test_df = pd.read_csv('/kaggle/input/titanic/test.csv')
 submission_df = pd.DataFrame(columns=['PassengerId', 'Survived'])
 submission_df['PassengerId'] = test_df['PassengerId']
submission_df['Survived'] = y_pred
submission_df.to_csv('submission.csv', header=True, index=False)
 submission_df.head(10 )<set_options>
def print_score(m : xgb):
res = ['mae train: ', mean_absolute_error(m.predict(X_train), y_train),
'mae val: ', mean_absolute_error(m.predict(X_valid), y_valid)]
if hasattr(m, 'oob_score_'): res.append(m.oob_score_)
 print(res )
warnings.filterwarnings('ignore')
 pd.options.display.max_columns = 50
plt.style.use('ggplot')
<load_from_csv>
v_train = pd.read_csv('/kaggle/input/titanic/train.csv')
 v_test = pd.read_csv('/kaggle/input/titanic/test.csv')
 idx = len(v_train )<concatenate>
rnd_mod_1 = RandomForestRegressor(n_estimators=40, min_samples_leaf=3, max_features='sqrt', n_jobs=-1)
v_train.drop('PassengerId', axis=1, inplace=True)
 v_test.drop('PassengerId', axis=1, inplace=True)
 v_merged = pd.concat([v_train, v_test], sort=False ).reset_index(drop=True )<load_from_csv>
rnd_mod_1.fit(X_train, y_train)
 print_score(rnd_mod_1)
def get_combined_data() :
train = pd.read_csv('/kaggle/input/titanic/train.csv')
 test = pd.read_csv('/kaggle/input/titanic/test.csv')
 targets = train.Survived
combined = train.append(test)
 combined.reset_index(inplace=True, drop=True)
 return combined<feature_engineering>
to_keep = fi[fi.imp>0.005].cols
print('Significant features: ', len(to_keep))
to_keep
def process_family() :
global combined
combined['FamilySize'] = combined['Parch'] + combined['SibSp'] + 1
combined['Alone'] = combined['FamilySize'].map(lambda s: 1
if s == 1 else 0)
 status('Family')
 return combined<feature_engineering>
X_keep = X[to_keep].copy()
X_train, X_valid = split_vals(X_keep, n_trn )
def family_survival() :
global combined

 combined['Last_Name'] = combined['Name'].apply(
 lambda x: str.split(x, ",")[0])
 default_survival_rate = 0.5
combined['Family_Survival'] = default_survival_rate
for grp, grp_df in combined[[
'Survived', 'Name', 'Last_Name', 'Fare', 'Ticket', 'PassengerId',
'SibSp', 'Parch', 'Age', 'Cabin'
]].groupby(['Last_Name', 'Fare']):
if(len(grp_df)!= 1):
for ind, row in grp_df.iterrows() :
smax = grp_df.drop(ind)['Survived'].max()
smin = grp_df.drop(ind)['Survived'].min()
passID = row['PassengerId']
if(smax == 1.0):
combined.loc[combined['PassengerId'] ==
passID, 'Family_Survival'] = 1
elif(smin == 0.0):
combined.loc[combined['PassengerId'] ==
passID, 'Family_Survival'] = 0
for _, grp_df in combined.groupby('Ticket'):
if(len(grp_df)!= 1):
for ind, row in grp_df.iterrows() :
if(row['Family_Survival'] == 0)|(
 row['Family_Survival'] == 0.5):
smax = grp_df.drop(ind)['Survived'].max()
smin = grp_df.drop(ind)['Survived'].min()
passID = row['PassengerId']
if(smax == 1.0):
combined.loc[combined['PassengerId'] ==
passID, 'Family_Survival'] = 1
elif(smin == 0.0):
combined.loc[combined['PassengerId'] ==
passID, 'Family_Survival'] = 0
status('FamilySurvival')
 return combined<define_variables>
rnd_mod_2.fit(X_train, y_train)
 print_score(rnd_mod_2 )
def get_titles() :
title_dictionary = {
'Capt': 'Dr/Clergy/Mil',
'Col': 'Dr/Clergy/Mil',
'Major': 'Dr/Clergy/Mil',
'Jonkheer': 'Honorific',
'Don': 'Honorific',
'Dona': 'Honorific',
'Sir': 'Honorific',
'Dr': 'Dr/Clergy/Mil',
'Rev': 'Dr/Clergy/Mil',
'the Countess': 'Honorific',
'Mme': 'Mrs',
'Mlle': 'Miss',
'Ms': 'Mrs',
'Mr': 'Mr',
'Mrs': 'Mrs',
'Miss': 'Miss',
'Master': 'Master',
'Lady': 'Honorific'
}
combined['Title'] = combined['Name'].map(
 lambda name: name.split(',')[1].split('.')[0].strip())
 combined['Title'] = combined.Title.map(title_dictionary)
 status('Title')
 return combined<categorify>
val_perc_full = 0.12
n_valid_full = int(val_perc_full * len(train))
n_trn_full = len(train)-n_valid_full
X_full = train.drop(columns = ['winPlacePerc'])
 y = train['winPlacePerc']
X_full = X_full[to_keep]
X_train, X_valid = split_vals(X_full, n_trn_full)
 y_train, y_valid = split_vals(y, n_trn_full)
 print('Sample train shape: ', X_train.shape,
'Sample target shape: ', y_train.shape,
'Sample validation shape: ', X_valid.shape )
def process_names() :
global combined
combined.drop('Name', axis=1, inplace=True)
 titles_dummies = pd.get_dummies(combined['Title'], prefix='Title')
 combined = pd.concat([combined, titles_dummies], axis=1)
 combined.drop('Title', axis=1, inplace=True)
 status('names')
 return combined<feature_engineering>
rnd_mod_3.fit(X_train, y_train)
 print_score(rnd_mod_3 )
def process_age() :
global combined
combined['Age'] = combined.groupby(
 ['Pclass', 'Sex'])['Age'].apply(lambda x: x.fillna(x.median()))
status('Age')
 return combined<categorify>
test_pred = test[to_keep].copy()
test_pred.fillna(0, inplace=True)
 test_pred.head()
def age_binner() :
global combined
names = ['less2', '2-18', '18-35', '35-65', '65plus']
combined['AgeBin'] = pd.qcut(combined['Age'],q = 5, labels = names)
 age_dummies = pd.get_dummies(combined['AgeBin'], prefix='AgeBin')
 combined = pd.concat([combined, age_dummies], axis=1)
 combined.drop('AgeBin', inplace=True, axis=1)
 combined.drop('Age', inplace=True, axis=1)
 status('Age Bins')
 return combined<feature_engineering>
predictions = np.clip(a = rnd_mod_3.predict(test_pred), a_min = 0.0, a_max = 1.0)
 pred_df = pd.DataFrame({'Id' : test['Id'], 'winPlacePerc' : predictions})
 pred_df.to_csv("submission.csv", index=False )