Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
skewness = feat_num.apply(lambda x: skew(x))
skewness = skewness[abs(skewness)> 0.5]
print("There are {} skewed numerical features after Box Cox transform".format(skewness.shape[0]))
print("Mean skewnees: {}".format(np.mean(skewness)))
 skewness.sort_values(ascending=False )<feature_engineering>
df_sub = pd.read_csv(".. /input/dataset/score.csv" )
data_features['TotalSF']=data_features['TotalBsmtSF'] + data_features['1stFlrSF'] + data_features['2ndFlrSF']
data_features['Total_Bathrooms'] =(data_features['FullBath'] +(0.5 * data_features['HalfBath'])+
data_features['BsmtFullBath'] +(0.5 * data_features['BsmtHalfBath']))
data_features['Total_porch_sf'] =(data_features['OpenPorchSF'] + data_features['3SsnPorch'] +
data_features['EnclosedPorch'] + data_features['ScreenPorch'] +
data_features['WoodDeckSF'])
 data_features['haspool'] = data_features['PoolArea'].apply(lambda x: 1 if x > 0 else 0)
 data_features['hasgarage'] = data_features['GarageArea'].apply(lambda x: 1 if x > 0 else 0)
 data_features['hasbsmt'] = data_features['TotalBsmtSF'].apply(lambda x: 1 if x > 0 else 0)
 data_features['hasfireplace'] = data_features['Fireplaces'].apply(lambda x: 1 if x > 0 else 0)
<drop_column>
df_test = pd.read_csv(".. /input/pubg-finish-placement-prediction/test_V2.csv" )
data_features = data_features.drop(['MasVnrArea', 'OpenPorchSF', 'WoodDeckSF', 'BsmtFinSF1','2ndFlrSF'], axis=1)
 print('data_features size:', data_features.shape)
<prepare_x_and_y>
df_sub = df_sub.merge(df_test[["Id", "matchId", "groupId", "maxPlace", "numGroups"]], on="Id", how="left")
 df_sub_group = df_sub.groupby(["matchId", "groupId"] ).first().reset_index()
df_sub_group["rank"] = df_sub_group.groupby(["matchId"])["winPlacePerc"].rank()
df_sub_group = df_sub_group.merge(
 df_sub_group.groupby("matchId")["rank"].max().to_frame("max_rank" ).reset_index() ,
on="matchId", how="left")
 df_sub_group["adjusted_perc"] =(df_sub_group["rank"] - 1)/(df_sub_group["numGroups"] - 1)
 df_sub = df_sub.merge(df_sub_group[["adjusted_perc", "matchId", "groupId"]], on=["matchId", "groupId"], how="left")
 df_sub["winPlacePerc"] = df_sub["adjusted_perc"]
y_train = train['SalePrice']<categorify>
df_sub.loc[df_sub.maxPlace == 0, "winPlacePerc"] = 0
df_sub.loc[df_sub.maxPlace == 1, "winPlacePerc"] = 1
data_features = data_features.drop("SalePrice", axis = 1)
 final_features = pd.get_dummies(data_features)
 print(final_features.shape)
 X = final_features.iloc[:len(y), :]
X_test = final_features.iloc[len(y):, :]
X.shape, y_train.shape, X_test.shape
print(X.shape,y_train.shape,X_test.shape )<train_model>
subset = df_sub.loc[df_sub.maxPlace > 1]
gap = 1.0 /(subset.maxPlace.values - 1)
 new_perc = np.around(subset.winPlacePerc.values / gap)* gap
df_sub.loc[df_sub.maxPlace > 1, "winPlacePerc"] = new_perc
overfit = []
for i in X.columns:
counts = X[i].value_counts()
zeros = counts.iloc[0]
if zeros / len(X)* 100 > 99.95:
overfit.append(i)
 overfit = list(overfit)
 overfit.append('MSZoning_C(all)')
 X = X.drop(overfit, axis=1 ).copy()
X_test = X_test.drop(overfit, axis=1 ).copy()
print(X.shape,y_train.shape,X_test.shape )<import_modules>
df_sub.loc[(df_sub.maxPlace > 1)&(df_sub.numGroups == 1), "winPlacePerc"] = 0
assert df_sub["winPlacePerc"].isnull().sum() == 0
<compute_train_metric><EOS> 
df_sub[["Id", "winPlacePerc"]].to_csv("submission.csv", index=False)
 print(df_sub['winPlacePerc'].describe() )