Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
<SOS> metric: MAE Kaggle data source: pubg-finish-placement-prediction-(kernels-only)<predict_on_test>
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
pred = MODELS['svc']['best_estimator'].predict(x_test )<save_to_csv>
train = pd.read_csv('.. /input/pubg-finish-placement-prediction/train_V2.csv')
 test = pd.read_csv('.. /input/pubg-finish-placement-prediction/test_V2.csv' )
submission = pd.DataFrame({'PassengerId': df_test_raw['PassengerId'], 'Survived': pred})
 submission.to_csv('submission.csv', index=False )<set_options>
train['totalDistance']=train['rideDistance']+train['walkDistance']+train['swimDistance']
train['killsWithoutMoving']=(( train['kills']>0)&(train['totalDistance']==0))
train['headshot_rate']=train['headshotKills']/train['kills']
train['playersJoined'] = train.groupby('matchId')['matchId'].transform('count')
 print(train.shape)
 train.drop(train[train['winPlacePerc'].isnull() ].index,inplace=True)
 train.drop(train[train['killsWithoutMoving']==True].index,inplace=True)
 train.drop(train[train['roadKills']>10].index,inplace=True)
 train.drop(train[train['kills']>35].index,inplace=True)
 train.drop(train[(( train['headshot_rate']==1)&(train['kills']>9)) ].index,inplace=True)
 train.drop(train[train['longestKill']>=1000].index,inplace=True)
 train.drop(train[train['walkDistance']>=10000].index,inplace=True)
 train.drop(train[train['rideDistance']>=20000].index,inplace=True)
 train.drop(train[train['swimDistance']>=2000].index,inplace=True)
 train.drop(train[train['weaponsAcquired']>=80].index,inplace=True)
 train.drop(train[train['heals']>=40].index,inplace=True)
 train.drop(train[(( train['totalDistance']==0)&(train['weaponsAcquired']>3)) ].index,inplace=True)
 print(train.shape )
import time
import warnings
import numpy as np
import pandas as pd<set_options>
train['killsNorm'] = train['kills']*(( 100-train['playersJoined'])/100 + 1)
 train['headshotKillsNorm'] = train['headshotKills']*(( 100-train['playersJoined'])/100 + 1)
 train['killPlaceNorm'] = train['killPlace']*(( 100-train['playersJoined'])/100 + 1)
 train['killPointsNorm'] = train['killPoints']*(( 100-train['playersJoined'])/100 + 1)
 train['killStreaksNorm'] = train['killStreaks']*(( 100-train['playersJoined'])/100 + 1)
 train['longestKillNorm'] = train['longestKill']*(( 100-train['playersJoined'])/100 + 1)
 train['roadKillsNorm'] = train['roadKills']*(( 100-train['playersJoined'])/100 + 1)
 train['teamKillsNorm'] = train['teamKills']*(( 100-train['playersJoined'])/100 + 1)
 train['damageDealtNorm'] = train['damageDealt']*(( 100-train['playersJoined'])/100 + 1)
 train['DBNOsNorm'] = train['DBNOs']*(( 100-train['playersJoined'])/100 + 1)
 train['revivesNorm'] = train['revives']*(( 100-train['playersJoined'])/100 + 1)
 train = train.drop([ 'kills', 'headshotKills', 'killPlace', 'killPoints', 'killStreaks',
'longestKill', 'roadKills', 'teamKills', 'damageDealt', 'DBNOs', 'revives'],axis=1 )
sns.set_style("whitegrid")
 warnings.filterwarnings('ignore' )<load_from_csv>
target='winPlacePerc'
features=list(train.columns)
 features.remove("Id")
 features.remove("matchId")
 features.remove("groupId")
 features.remove("matchType")
 features.remove("killsWithoutMoving")
 features.remove("headshot_rate")
 features.remove(target)
 sample = 500000
df_sample = train.sample(sample)
 x_train=df_sample[features]
y_train=df_sample[target]
train=pd.read_csv(".. /input/digit-recognizer/train.csv")
 submit=pd.read_csv(".. /input/digit-recognizer/test.csv")
 print(typeInfo(train))
print(typeInfo(submit)) 
<prepare_x_and_y>
random_seed=1
sample = 500000
x_train,x_val,y_train,y_val=train_test_split(x_train,y_train,test_size=0.1,random_state=random_seed)
 model=RandomForestRegressor(n_estimators=70,min_samples_leaf=3,max_features=0.5,n_jobs=-1 )
x_train = train.drop('label', axis=1)
 y_train = train['label'] 
<split>
%%time
model.fit(x_train,y_train )
x = x_train
y = y_train
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.15, random_state=0 )<categorify>
print('mae train:',mean_absolute_error(model.predict(x_train),y_train))
print('mae train:',mean_absolute_error(model.predict(x_val),y_val))
x_train = x_train.values.reshape(-1,28,28,1)
 x_test = x_test.values.reshape(-1,28,28,1)
 submit = submit.values.reshape(-1,28,28,1 )<choose_model_class>
test['totalDistance']=test['rideDistance']+test['walkDistance']+test['swimDistance']
test['headshot_rate']=test['headshotKills']/test['kills']
test['playersJoined'] = test.groupby('matchId')['matchId'].transform('count')
 test['killsNorm'] = test['kills']*(( 100-test['playersJoined'])/100 + 1)
 test['headshotKillsNorm'] = test['headshotKills']*(( 100-test['playersJoined'])/100 + 1)
 test['killPlaceNorm'] = test['killPlace']*(( 100-test['playersJoined'])/100 + 1)
 test['killPointsNorm'] = test['killPoints']*(( 100-test['playersJoined'])/100 + 1)
 test['killStreaksNorm'] = test['killStreaks']*(( 100-test['playersJoined'])/100 + 1)
 test['longestKillNorm'] = test['longestKill']*(( 100-test['playersJoined'])/100 + 1)
 test['roadKillsNorm'] = test['roadKills']*(( 100-test['playersJoined'])/100 + 1)
 test['teamKillsNorm'] = test['teamKills']*(( 100-test['playersJoined'])/100 + 1)
 test['damageDealtNorm'] = test['damageDealt']*(( 100-test['playersJoined'])/100 + 1)
 test['DBNOsNorm'] = test['DBNOs']*(( 100-test['playersJoined'])/100 + 1)
 test['revivesNorm'] = test['revives']*(( 100-test['playersJoined'])/100 + 1)
 test = test.drop([ 'kills', 'headshotKills', 'killPlace', 'killPoints', 'killStreaks',
'longestKill', 'roadKills', 'teamKills', 'damageDealt', 'DBNOs', 'revives'],axis=1 )
model = Sequential()
model.add(Conv2D(64,(3, 3), input_shape=(28,28,1),padding="SAME"))
model.add(BatchNormalization(axis=-1))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
 model.add(Conv2D(64,(3, 3),padding="SAME"))
model.add(BatchNormalization(axis=-1))
model.add(Activation('relu'))
model.add(Conv2D(128,(3, 3),padding="SAME"))
model.add(BatchNormalization(axis=-1))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
 model.add(Conv2D(128,(3, 3),padding="SAME"))
model.add(BatchNormalization(axis=-1))
model.add(Activation('relu'))
model.add(Conv2D(192,(3, 3),padding="SAME"))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
 model.add(Conv2D(192,(5, 5),strides=2,padding="SAME"))
model.add(Activation('relu'))
model.add(Flatten() )<choose_model_class>
x_test=test[features]
pred=model.predict(x_test)
 test['winPlacePerc']=pred
submission=test[['Id','winPlacePerc']]
submission.head()
<choose_model_class><EOS> 
submission.to_csv('submission.csv',index=False )