Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
<SOS> metric: MAE Kaggle data source: pubg-finish-placement-prediction-(kernels-only)<load_from_csv>
warnings.filterwarnings('ignore')
 train = pd.read_csv(".. /input/train.csv")
 train.head()
train = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv' )<feature_engineering>
test = pd.read_csv(".. /input/test.csv")
 test.head()
lam = 0.0
train["SalePrice"] = boxcox1p(train["SalePrice"], lam )<prepare_x_and_y>
train["distance"] = train["rideDistance"]+train["walkDistance"]+train["swimDistance"]
train["skill"] = train["headshotKills"]+train["roadKills"]
train.head()
ntrain = train.shape[0]
ntest = test.shape[0]
y_train = train.SalePrice.values
all_data = pd.concat(( train, test)).reset_index(drop=True)
 all_data.drop(['SalePrice'], axis=1, inplace=True)
 print("all_data size is : {}".format(all_data.shape))<count_missing_values>
test["distance"] = test["rideDistance"]+test["walkDistance"]+test["swimDistance"]
test["skill"] = test["headshotKills"]+test["roadKills"]
test["distance"].head()
all_data.isnull()<count_missing_values>
predictors = [ "kills",
"maxPlace",
"numGroups",
"distance",
"boosts",
"heals",
"revives",
"killStreaks",
"weaponsAcquired",
"winPoints",
"skill",
"assists",
"damageDealt",
"DBNOs",
"killPlace",
"killPoints",
"vehicleDestroys",
"longestKill"
]
x_train = train[predictors]
x_train.head()
all_data.isnull().sum()<create_dataframe>
y_train = train["winPlacePerc"]
y_train.head()
all_data_na =(all_data.isnull().sum() / len(all_data)) * 100
all_data_na = all_data_na.drop(all_data_na[all_data_na == 0].index ).sort_values(ascending=False)[:30]
missing_data = pd.DataFrame({'Missing Ratio' :all_data_na})
 missing_data.head(20 )<data_type_conversions>
regressor = lgb.LGBMRegressor(objective='regression',num_leaves=5,
learning_rate=0.05, n_estimators=720,
max_bin = 20, bagging_fraction = 0.8,
bagging_freq = 5, feature_fraction = 0.8)
 regressor.fit(x_train, y_train )
all_data["PoolQC"] = all_data["PoolQC"].fillna("None" )<data_type_conversions>
scores = cross_val_score(regressor, x_train, y_train, cv=10)
 print(scores )
all_data["MiscFeature"] = all_data["MiscFeature"].fillna("None" )<data_type_conversions>
accuracy = scores.mean()
print(accuracy )
all_data["Alley"] = all_data["Alley"].fillna("None" )<data_type_conversions>
y_predict = regressor.predict(x_test)
 print(y_predict )
all_data["Fence"] = all_data["Fence"].fillna("None" )<data_type_conversions>
y_predict[y_predict > 1] = 1
test['winPlacePercPredictions'] = y_predict
aux = test.groupby(['matchId','groupId'])['winPlacePercPredictions'].agg('mean' ).groupby('matchId' ).rank(pct=True ).reset_index()
aux.columns = ['matchId','groupId','winPlacePerc']
test = test.merge(aux, how='left', on=['matchId','groupId'])
 submission = test[['Id','winPlacePerc']]
all_data["FireplaceQu"] = all_data["FireplaceQu"].fillna("None" )<categorify>
submission.to_csv("kill_them_all.csv", index=False )
all_data["LotFrontage"] = all_data.groupby("Neighborhood")["LotFrontage"].transform(
 lambda x: x.fillna(x.median()))<data_type_conversions>
important_predictors = [ "kills",
"maxPlace",
"numGroups",
"distance",
"killStreaks",
"weaponsAcquired",
"winPoints",
"killPlace",
"killPoints",
"longestKill"
]
x_train = train[important_predictors]
x_train.head()
for col in('GarageType', 'GarageFinish', 'GarageQual', 'GarageCond'):
all_data[col] = all_data[col].fillna('None' )<data_type_conversions>
regressor = lgb.LGBMRegressor(objective='regression',num_leaves=5,
learning_rate=0.05, n_estimators=720,
max_bin = 20, bagging_fraction = 0.8,
bagging_freq = 5, feature_fraction = 0.8)
 regressor.fit(x_train, y_train )
for col in('GarageYrBlt', 'GarageArea', 'GarageCars'):
all_data[col] = all_data[col].fillna(0 )<data_type_conversions>
y_predict = regressor.predict(x_test)
 print(y_predict )
for col in('BsmtFinSF1', 'BsmtFinSF2', 'BsmtUnfSF','TotalBsmtSF', 'BsmtFullBath', 'BsmtHalfBath'):
all_data[col] = all_data[col].fillna(0 )<data_type_conversions>
y_predict[y_predict > 1] = 1
test['winPlacePercPredictions'] = y_predict
aux = test.groupby(['matchId','groupId'])['winPlacePercPredictions'].agg('mean' ).groupby('matchId' ).rank(pct=True ).reset_index()
for col in('BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2'):
all_data[col] = all_data[col].fillna('None' )<data_type_conversions>
aux.columns = ['matchId','groupId','winPlacePerc']
test = test.merge(aux, how='left', on=['matchId','groupId'])
 test.head()
all_data["MasVnrType"] = all_data["MasVnrType"].fillna("None")
 all_data["MasVnrArea"] = all_data["MasVnrArea"].fillna(0 )<data_type_conversions>
scores = cross_val_score(regressor, x_train, y_train, cv=10)
 print(scores )
<drop_column><EOS> 
accuracy = scores.mean()
print(accuracy )