Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
all_data_missing =(all_data.isnull().sum() / len(all_data)) * 100
all_data_missing = all_data_missing.drop(all_data_missing[all_data_missing == 0].index ).sort_values(ascending=False)
 missing_data = pd.DataFrame({'Missing Percentage':all_data_missing})
 missing_data.head(30 )<data_type_conversions>
train = pd.read_csv(".. /input/pubg-finish-placement-prediction/train_V2.csv")
 test = pd.read_csv(".. /input/pubg-finish-placement-prediction/test_V2.csv")
 gender_submission = pd.read_csv(".. /input/pubg-finish-placement-prediction/sample_submission_V2.csv" )
for col in('PoolQC', 'MiscFeature', 'Alley', 'Fence', 'FireplaceQu', 'GarageType', 'GarageFinish', 'GarageQual', 'GarageCond', 'BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2', 'MasVnrType', 'MSSubClass'):
all_data[col] = all_data[col].fillna('None' )<data_type_conversions>
data = pd.concat([train, test], sort = True)
 print(len(train), len(test), len(data))
for col in('GarageYrBlt', 'GarageArea', 'GarageCars', 'BsmtFinSF1', 'BsmtFinSF2', 'BsmtUnfSF','TotalBsmtSF', 'BsmtFullBath', 'BsmtHalfBath', 'MasVnrArea'):
all_data[col] = all_data[col].fillna(0 )<data_type_conversions>
delete_columns = ['Id', 'groupId', 'matchId']
data.drop(delete_columns, axis = 1, inplace = True )
for col in('MSZoning', 'Electrical', 'KitchenQual', 'Exterior1st', 'Exterior2nd', 'SaleType', 'Functional', 'Utilities'):
all_data[col] = all_data[col].fillna(all_data[col].mode() [0] )<feature_engineering>
data['fightRange'] =(data['kills'] + data['DBNOs'])/ data['walkDistance'] * 100
data['fightRange'].replace([np.inf,-np.inf], np.nan, inplace = True)
 data['fightRange'].fillna(0, inplace = True)
 data['surpriseAttackRatio'] =(data['kills'] + data['DBNOs'])/ data['damageDealt'] * 100
data['surpriseAttackRatio'].replace([np.inf,-np.inf], np.nan, inplace = True)
 data['surpriseAttackRatio'].fillna(0, inplace = True )
all_data['LotFrontage'] = all_data.groupby('Neighborhood')['LotFrontage'].apply(lambda x: x.fillna(x.median()))<create_dataframe>
defaultmatch = ['squad-fpp', 'duo', 'solo-fpp', 'squad', 'duo-fpp', 'solo',
'normal-squad-fpp', 'normal-solo-fpp','normal-duo-fpp',
'normal-duo', 'normal-squad', 'normal-solo']
crashmatch = ['crashfpp', 'crashtpp']
flarematch = ['flarefpp', 'flaretpp']
data['defaultMatch'] = data['matchType'].replace(defaultmatch, 1)
 data['defaultMatch'].replace(crashmatch, 0, inplace=True)
 data['defaultMatch'].replace(flarematch, 0, inplace=True)
 data['crashMatch'] = data['matchType'].replace(crashmatch, 1)
 data['crashMatch'].replace(defaultmatch, 0, inplace=True)
 data['crashMatch'].replace(flarematch, 0, inplace=True)
 data['flareMatch'] = data['matchType'].replace(flarematch, 1)
 data['flareMatch'].replace(defaultmatch, 0, inplace=True)
 data['flareMatch'].replace(crashmatch, 0, inplace=True )
all_data_missing =(all_data.isnull().sum() / len(all_data)) * 100
all_data_missing = all_data_missing.drop(all_data_missing[all_data_missing == 0].index ).sort_values(ascending=False)
 missing_data = pd.DataFrame({'Missing Ratio':all_data_missing})
 missing_data.head(30 )<data_type_conversions>
data.drop('matchType', axis = 1, inplace = True )
for col in('MSSubClass', 'OverallCond', 'YrSold', 'MoSold'):
all_data[col] = all_data[col].astype(str)
 all_data.info()<filter>
train = data[:len(train)]
test = data[len(train):]
train = train.dropna()
y_test_pred = 0
skewness = skewness[abs(skewness)> 0.75]
print("Total number of features requiring a fix for skewness is: {}".format(skewness.shape[0]))<feature_engineering>
winner_train = train['winPlacePerc']
train_valid_pred = winner_train * 0
train_source = train.drop('winPlacePerc', axis = 1)
 test_source = test.drop('winPlacePerc', axis = 1 )
skewed_features = skewness.index
lam = 0.15
for feature in skewed_features:
all_data[feature] = boxcox1p(all_data[feature], lam )<feature_engineering>
import lightgbm as lgb
from sklearn.model_selection import KFold
all_data['TotalSF'] = all_data['TotalBsmtSF'] + all_data['1stFlrSF'] + all_data['2ndFlrSF']<define_variables>
params = {'task' : 'train',
'boosting_type' : 'gbdt',
'objective' : 'regression',
'metric' : {'l2'},
'num_leaves' : 31,
'learning_rate' : 0.1,
'feature_fraction' : 0.9,
'bagging_fraction' : 0.8,
'bagging_freq': 5,
'verbose' : 0,
}
low_var_cat = [col for col in all_data.select_dtypes(exclude=['number'])if 1 - sum(all_data[col] == mode(all_data[col])) /len(all_data)< 0.03]
low_var_cat<drop_column>
max_rounds = 1200
num_Fold = 5
kf = KFold(n_splits = num_Fold, random_state = 1, shuffle = True)
 for i,(train_index,val_index)in enumerate(kf.split(train_source)) :
y_train = winner_train.iloc[train_index].copy()
X_train = train_source.iloc[train_index,:].copy()
test_set = test_source.copy()
print("Fold", i)
 fit_model = lgb.train(params,
train_set = lgb.Dataset(X_train, y_train),
num_boost_round = max_rounds,
verbose_eval = 50)
 test_pred = fit_model.predict(test_set)
 print("test_pred_head:", test_pred[:4], "
")
 y_test_pred += test_pred
print("Train is Done.")
 y_test_pred /= num_Fold
print("Predict_Avg:", y_test_pred )
all_data = all_data.drop(['Street', 'Utilities', 'Condition2', 'RoofMatl', 'Heating', 'PoolQC'], axis=1 )<categorify>
sub = pd.DataFrame(gender_submission['Id'])
 sub['winPlacePerc'] = list(map(float, y_test_pred))
sub.to_csv("submission.csv", index = False )