Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
test_set.isnull().sum()<create_dataframe>
df_trn = pd.read_csv('.. /input/pubg-finish-placement-prediction/train.csv', nrows=None)
 df_trn = reduce_mem_usage(df_trn)
 df_tst = pd.read_csv('.. /input/pubg-finish-placement-prediction/test.csv', nrows=None)
 df_tst = reduce_mem_usage(df_tst )
fare_set = train_set[['Fare','Survived']].copy()
cont_plot(fare_set, 'Fare', 'Survived', survival_palette, [1, 0], range(0,550,50))<count_values>
lgbm_trn = pd.read_csv('.. /input/pubg-survivor-kit/oof_lgbm1_reg.csv')
 lgbm_trn.columns = [c if 'winPlacePerc' not in c else c+'Pred' for c in lgbm_trn.columns]
lgbm_tst = pd.read_csv('.. /input/pubg-survivor-kit/sub_lgbm1_reg.csv')
 lgbm_tst.columns = [c if 'winPlacePerc' not in c else c+'Pred' for c in lgbm_tst.columns]
combined_set = [train_set, test_set]
for dataset in combined_set:
dataset["Age"].fillna(dataset["Age"].median() , inplace=True)
 dataset["Fare"].fillna(dataset["Fare"].median() , inplace=True)
 train_set["Embarked"].fillna(train_set["Embarked"].value_counts().index[0], inplace=True )<count_missing_values>
df_trn2 = pd.concat([df_trn, lgbm_trn['winPlacePercPred']], axis=1)
 df_tst2 = pd.concat([df_tst, lgbm_tst['winPlacePercPred']], axis=1 )
train_set.isnull().sum()<count_missing_values>
df_trn3 = df_trn2.groupby(['matchId','groupId'])['winPlacePercPred'].agg('mean' ).groupby('matchId' ).rank(pct=True ).reset_index()
df_trn3.columns = [c if 'winPlacePerc' not in c else c+'_Rank' for c in df_trn3.columns]
df_trn3 = df_trn3.merge(df_trn2, how='left', on=['matchId','groupId'] )
test_set.isnull().sum()<feature_engineering>
print('MAE by default: {:.4f}'.format(
 mean_absolute_error(df_trn3['winPlacePerc'], df_trn3['winPlacePercPred'])
)
 )
for dataset in combined_set:
dataset['Family'] = ''
dataset.loc[dataset['FamilySize'] == 0, 'Family'] = 'alone'
dataset.loc[(dataset['FamilySize'] > 0)&(dataset['FamilySize'] <= 3), 'Family'] = 'small'
dataset.loc[(dataset['FamilySize'] > 3)&(dataset['FamilySize'] <= 6), 'Family'] = 'medium'
dataset.loc[dataset['FamilySize'] > 6, 'Family'] = 'large'<define_variables>
print('MAE after group ranking: {:.4f}'.format(
 mean_absolute_error(df_trn3['winPlacePerc'], df_trn3['winPlacePercPred_Rank'])
)
 )
title_dict = {
"Mr" : "Mr",
"Miss" : "Miss",
"Mrs" : "Mrs",
"Master" : "Master",
"Dr": "Scholar",
"Rev": "Religious",
"Col": "Officer",
"Major": "Officer",
"Mlle": "Miss",
"Don": "Noble",
"the Countess":"Noble",
"Ms": "Mrs",
"Mme": "Mrs",
"Capt": "Noble",
"Lady" : "Noble",
"Sir" : "Noble",
"Jonkheer": "Noble"
}
for dataset in combined_set:
dataset['TitleGroup'] = dataset.Title.map(title_dict )<count_missing_values>
df_tst3 = df_tst2.groupby(['matchId','groupId'])['winPlacePercPred'].agg('mean' ).groupby('matchId' ).rank(pct=True ).reset_index()
df_tst3.columns = [c if 'winPlacePerc' not in c else c+'_Rank' for c in df_tst3.columns]
df_tst3 = df_tst2.merge(df_tst3, how='left', on=['matchId','groupId'] )
print(test_set[test_set['TitleGroup'].isnull() == True] )<feature_engineering>
del lgbm_tst['winPlacePercPred']
lgbm_tst['winPlacePerc'] = df_tst3['winPlacePercPred_Rank']
<prepare_x_and_y><EOS> 
lgbm_tst.to_csv('sub_lgbm_group_ranked_within_game.csv', index=False )