Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
<SOS> metric: MAE Kaggle data source: pubg-finish-placement-prediction-(kernels-only)<prepare_x_and_y>
%load_ext autoreload
%autoreload 2
%matplotlib inline
y_train = train['Survived'].ravel()
train = train.drop(['Survived'], axis=1)
 x_train = train.values
x_test = test.values<categorify>
from fastai.imports import *
from pandas_summary import DataFrameSummary
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from IPython.display import display
from sklearn import metrics
from sklearn.model_selection import train_test_split
import gc
et_oof_train, et_oof_test = get_oof(et, x_train, y_train, x_test)
 rf_oof_train, rf_oof_test = get_oof(rf,x_train, y_train, x_test)
 ada_oof_train, ada_oof_test = get_oof(ada, x_train, y_train, x_test)
 gb_oof_train, gb_oof_test = get_oof(gb,x_train, y_train, x_test)
 svc_oof_train, svc_oof_test = get_oof(svc,x_train, y_train, x_test)
 print("Training is complete" )<compute_test_metric>
def set_plot_sizes(sml, med, big):
plt.rc('font', size=sml)
 plt.rc('axes', titlesize=sml)
 plt.rc('axes', labelsize=med)
 plt.rc('xtick', labelsize=sml)
 plt.rc('ytick', labelsize=sml)
 plt.rc('legend', fontsize=sml)
 plt.rc('figure', titlesize=big)
 def parallel_trees(m, fn, n_jobs=8):
return list(ProcessPoolExecutor(n_jobs ).map(fn, m.estimators_))
def draw_tree(t, df, size=10, ratio=0.6, precision=0):

 s=export_graphviz(t, out_file=None, feature_names=df.columns, filled=True,
special_characters=True, rotate=True, precision=precision)
 IPython.display.display(graphviz.Source(re.sub('Tree {',
f'Tree {{ size={size}; ratio={ratio}', s)))
 def combine_date(years, months=1, days=1, weeks=None, hours=None, minutes=None,
seconds=None, milliseconds=None, microseconds=None, nanoseconds=None):
years = np.asarray(years)- 1970
months = np.asarray(months)- 1
days = np.asarray(days)- 1
types =('<M8[Y]', '<m8[M]', '<m8[D]', '<m8[W]', '<m8[h]',
'<m8[m]', '<m8[s]', '<m8[ms]', '<m8[us]', '<m8[ns]')
 vals =(years, months, days, weeks, hours, minutes, seconds,
milliseconds, microseconds, nanoseconds)
 return sum(np.asarray(v, dtype=t)for t, v in zip(types, vals)
 if v is not None)
 def get_sample(df,n):

 idxs = sorted(np.random.permutation(len(df)) [:n])
 return df.iloc[idxs].copy()
def add_datepart(df, fldname, drop=True, time=False):

 fld = df[fldname]
fld_dtype = fld.dtype
if isinstance(fld_dtype, pd.core.dtypes.dtypes.DatetimeTZDtype):
fld_dtype = np.datetime64
if not np.issubdtype(fld_dtype, np.datetime64):
df[fldname] = fld = pd.to_datetime(fld, infer_datetime_format=True)
 targ_pre = re.sub('[Dd]ate$', '', fldname)
 attr = ['Year', 'Month', 'Week', 'Day', 'Dayofweek', 'Dayofyear',
'Is_month_end', 'Is_month_start', 'Is_quarter_end', 'Is_quarter_start', 'Is_year_end', 'Is_year_start']
if time: attr = attr + ['Hour', 'Minute', 'Second']
for n in attr: df[targ_pre + n] = getattr(fld.dt, n.lower())
 df[targ_pre + 'Elapsed'] = fld.astype(np.int64)// 10 ** 9
if drop: df.drop(fldname, axis=1, inplace=True)
 def is_date(x): return np.issubdtype(x.dtype, np.datetime64)
 def train_cats(df):

 for n,c in df.items() :
if is_string_dtype(c): df[n] = c.astype('category' ).cat.as_ordered()
def apply_cats(df, trn):

 for n,c in df.items() :
if(n in trn.columns)and(trn[n].dtype.name=='category'):
df[n] = pd.Categorical(c, categories=trn[n].cat.categories, ordered=True)
 def fix_missing(df, col, name, na_dict):

 if is_numeric_dtype(col):
if pd.isnull(col ).sum() or(name in na_dict):
df[name+'_na'] = pd.isnull(col)
 filler = na_dict[name] if name in na_dict else col.median()
df[name] = col.fillna(filler)
 na_dict[name] = filler
return na_dict
def numericalize(df, col, name, max_n_cat):

 if not is_numeric_dtype(col)and(max_n_cat is None or len(col.cat.categories)>max_n_cat):
df[name] = col.cat.codes+1
def scale_vars(df, mapper):
warnings.filterwarnings('ignore', category=sklearn.exceptions.DataConversionWarning)
 if mapper is None:
map_f = [([n],StandardScaler())for n in df.columns if is_numeric_dtype(df[n])]
mapper = DataFrameMapper(map_f ).fit(df)
 df[mapper.transformed_names_] = mapper.transform(df)
 return mapper
def proc_df(df, y_fld=None, skip_flds=None, ignore_flds=None, do_scale=False, na_dict=None,
preproc_fn=None, max_n_cat=None, subset=None, mapper=None):

 if not ignore_flds: ignore_flds=[]
if not skip_flds: skip_flds=[]
if subset: df = get_sample(df,subset)
 else: df = df.copy()
ignored_flds = df.loc[:, ignore_flds]
df.drop(ignore_flds, axis=1, inplace=True)
 if preproc_fn: preproc_fn(df)
 if y_fld is None: y = None
else:
if not is_numeric_dtype(df[y_fld]): df[y_fld] = df[y_fld].cat.codes
y = df[y_fld].values
skip_flds += [y_fld]
df.drop(skip_flds, axis=1, inplace=True)
 if na_dict is None: na_dict = {}
else: na_dict = na_dict.copy()
na_dict_initial = na_dict.copy()
for n,c in df.items() : na_dict = fix_missing(df, c, n, na_dict)
 if len(na_dict_initial.keys())> 0:
df.drop([a + '_na' for a in list(set(na_dict.keys())- set(na_dict_initial.keys())) ], axis=1, inplace=True)
 if do_scale: mapper = scale_vars(df, mapper)
 for n,c in df.items() : numericalize(df, c, n, max_n_cat)
 df = pd.get_dummies(df, dummy_na=True)
 df = pd.concat([ignored_flds, df], axis=1)
 res = [df, y, na_dict]
if do_scale: res = res + [mapper]
return res
def rf_feat_importance(m, df):
return pd.DataFrame({'cols':df.columns, 'imp':m.feature_importances_}
).sort_values('imp', ascending=False)
 def set_rf_samples(n):

 forest._generate_sample_indices =(lambda rs, n_samples:
forest.check_random_state(rs ).randint(0, n_samples, n))
def reset_rf_samples() :

 forest._generate_sample_indices =(lambda rs, n_samples:
forest.check_random_state(rs ).randint(0, n_samples, n_samples))
def get_nn_mappers(df, cat_vars, contin_vars):
for v in contin_vars: df[v] = df[v].fillna(df[v].max() +100,)
 for v in cat_vars: df[v].fillna('
cat_maps = [(o, LabelEncoder())for o in cat_vars]
contin_maps = [([o], StandardScaler())for o in contin_vars]
return DataFrameMapper(cat_maps ).fit(df), DataFrameMapper(contin_maps ).fit(df )
rf_feature = rf.feature_importances(x_train,y_train)
 et_feature = et.feature_importances(x_train, y_train)
 ada_feature = ada.feature_importances(x_train, y_train)
 gb_feature = gb.feature_importances(x_train,y_train )<define_variables>
PATH_INPUT = "/kaggle/input/"
PATH_WORKING = "/kaggle/working/"
PATH_TMP = "/tmp/"
rf_features = [0.10474135, 0.21837029, 0.04432652, 0.02249159, 0.05432591, 0.02854371
,0.07570305, 0.01088129 , 0.24247496, 0.13685733 , 0.06128402]
et_features = [ 0.12165657, 0.37098307 ,0.03129623 , 0.01591611 , 0.05525811 , 0.028157
,0.04589793 , 0.02030357 , 0.17289562 , 0.04853517, 0.08910063]
ada_features = [0.028 , 0.008 , 0.012 , 0.05866667, 0.032 , 0.008
,0.04666667 , 0., 0.05733333, 0.73866667, 0.01066667]
gb_features = [ 0.06796144 , 0.03889349 , 0.07237845 , 0.02628645 , 0.11194395, 0.04778854
,0.05965792 , 0.02774745, 0.07462718, 0.4593142 , 0.01340093]<create_dataframe>
df_raw = pd.read_csv(f'{PATH_INPUT}train_V2.csv' )
cols = train.columns.values
feature_dataframe = pd.DataFrame({'features': cols,
'Random Forest feature importances': rf_features,
'Extra Trees feature importances': et_features,
'AdaBoost feature importances': ada_features,
'Gradient Boost feature importances': gb_features
} )<prepare_output>
df_test_raw = pd.read_csv(f'{PATH_INPUT}test_V2.csv' )
feature_dataframe['mean'] = feature_dataframe.mean(axis= 1)
 feature_dataframe.head(3 )<prepare_output>
df_raw.to_feather(f'{PATH_TMP}train_raw')
 df_test_raw.to_feather(f'{PATH_TMP}test_raw' )
base_predictions_train = pd.DataFrame({'RandomForest': rf_oof_train.ravel() ,
'ExtraTrees': et_oof_train.ravel() ,
'AdaBoost': ada_oof_train.ravel() ,
'GradientBoost': gb_oof_train.ravel()
})
 base_predictions_train.head()<concatenate>
df_raw["winPlace"] = round(df_raw["winPlacePerc"] /(1.0/(df_raw["maxPlace"] - 1)) )
x_train = np.concatenate(( et_oof_train, rf_oof_train, ada_oof_train, gb_oof_train, svc_oof_train), axis=1)
 x_test = np.concatenate(( et_oof_test, rf_oof_test, ada_oof_test, gb_oof_test, svc_oof_test), axis=1 )<predict_on_test>
df_raw.drop(labels="winPlace", axis=1, inplace=True )
gbm = xgb.XGBClassifier(
 n_estimators= 2000,
max_depth= 4,
min_child_weight= 2,
gamma=0.9,
subsample=0.8,
colsample_bytree=0.8,
objective= 'binary:logistic',
nthread= -1,
scale_pos_weight=1 ).fit(x_train, y_train)
 predictions = gbm.predict(x_test )<save_to_csv>
df_raw.isnull().sum().sort_values(ascending=False)/len(df_raw )
StackingSubmission = pd.DataFrame({ 'PassengerId': PassengerId,
'Survived': predictions })
 StackingSubmission.to_csv("gender_submission.csv", index=False )<import_modules>
df_raw.dropna(inplace=True)
 df_raw.shape
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, roc_curve, auc, roc_auc_score
from sklearn.preprocessing import label_binarize
from sklearn.svm import SVC
from itertools import cycle
from scipy import interp
from keras.optimizers import Adam
from keras.callbacks import Callback, EarlyStopping, ModelCheckpoint
from keras import backend as K
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Dense, Input, Dropout, Flatten
from keras.models import Model, load_model
from keras.preprocessing.image import ImageDataGenerator<load_from_csv>
df_test_raw.isnull().sum().any()
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )<load_from_csv>
train_cats(df_raw )
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )<split>
ids = df_test_raw["Id"]
X_train, X_valid, y_train, y_valid = train_test_split(train.drop(['label'], axis=1), train['label'], random_state = 0 )<categorify>
apply_cats(df_test_raw, df_raw )
X_train = X_train.values.reshape(-1,28,28,1)
 X_valid = X_valid.values.reshape(-1,28,28,1)
 y_train = label_binarize(y_train, classes=range(10))
y_valid = label_binarize(y_valid, classes=range(10))<compute_train_metric>
df, y, _ = proc_df(df_raw, 'winPlacePerc', skip_flds=["Id","groupId","matchId"], subset=100000 )
class RocAucEvaluation(Callback):
def __init__(self, validation_data=() , interval=1):
super(Callback, self ).__init__()
self.interval = interval
self.X_val, self.y_val = validation_data
def on_epoch_end(self, epoch, logs={}):
if epoch % self.interval == 0:
y_pred = self.model.predict(self.X_val, verbose=0)
 score = roc_auc_score(self.y_val, y_pred)
 print("
ROC-AUC - epoch: {:d} - score: {:.6f}".format(epoch+1, score))<init_hyperparams>
df_test, _, _ = proc_df(df_test_raw, skip_flds=["Id","groupId","matchId"] )
class CNN:
def __init__(self):
self.arguments = {
'batch_size': 64,
'epochs': 100,
'learning_rate': 1e-3,
'learning_rate_decay': 0,
'units': 128,
'drop_out_rate': 0.2,
'checkpoint_path': 'best_bilstm_model.hdf5',
'early_stop_patience': 10,
}
print('Building CNN Models...')
 print(self.arguments)
 def fit(self, X_train, y_train, X_valid, y_valid):
file_path = self.arguments['checkpoint_path']
check_point = ModelCheckpoint(file_path, monitor = "val_loss", verbose = 1,
save_best_only = True, mode = "min")
 ra_val = RocAucEvaluation(validation_data=(X_valid, y_valid), interval = 1)
 early_stop = EarlyStopping(monitor = "val_loss", mode = "min", patience = self.arguments['early_stop_patience'])
 inp = Input(shape=(28,28,1))
x = Conv2D(filters=20, kernel_size =(5, 5), activation="relu" )(inp)
 max_pool_x = MaxPooling2D(pool_size=(2,2))(x)
 y = Conv2D(filters=20, kernel_size =(5, 5), activation="relu" )(max_pool_x)
 max_pool_y = MaxPooling2D(pool_size=(2,2))(y)
 flat = Flatten()(max_pool_y)
 z = Dense(100, activation="relu" )(flat)
 z = Dropout(rate = self.arguments['drop_out_rate'] )(z)
 z = Dense(100, activation="relu" )(z)
 z = Dropout(rate = self.arguments['drop_out_rate'] )(z)
 output = Dense(10, activation="softmax" )(z)
 self.model = Model(inputs = inp, outputs = output)
 self.model.compile(loss = "categorical_crossentropy", optimizer = Adam(lr = self.arguments['learning_rate'],
decay = self.arguments['learning_rate_decay']), metrics = ["accuracy"])
 history = self.model.fit(X_train, y_train, batch_size = self.arguments['batch_size'], epochs = self.arguments['epochs'],
validation_data =(X_valid, y_valid), verbose = 1, callbacks = [ra_val, check_point, early_stop])
 self.model = load_model(file_path)
 print('Finished Building CNN Model as class attribute class.model')
 return self
def predict(self, X, batch_size, verbose):
return self.model.predict(X, batch_size = batch_size, verbose = verbose )<train_on_grid>
X_train, X_valid, y_train, y_valid = train_test_split(df, y, test_size=0.2)
 print(X_train.shape, X_valid.shape, y_train.shape, y_valid.shape )
cnn = CNN()
cnn.fit(X_train, y_train, X_valid, y_valid)
 cnn_pred = cnn.predict(X_valid, batch_size = cnn.arguments['batch_size'], verbose = 1 )<define_variables>
def mae(x,y): return abs(x-y ).mean()
def fixWinPlacePerc(X,y):
y = round(y /(1.0/(X - 1)))/(X - 1)
 return y
def print_score(m):
res = [mae(fixWinPlacePerc(X_train["maxPlace"], m.predict(X_train)) , y_train),
mae(fixWinPlacePerc(X_valid["maxPlace"], m.predict(X_valid)) , y_valid)]
print(res )
datagen = ImageDataGenerator(
 rotation_range=10,
zoom_range = 0.1,
width_shift_range=0.1,
height_shift_range=0.1,
)<define_variables>
%%time
m = RandomForestRegressor(n_estimators=10, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
train_gen = datagen.flow(X_train, y_train, batch_size=64)
 valid_gen = datagen.flow(X_valid, y_valid, batch_size=64 )<init_hyperparams>
gc.collect()
class CNN_Generator:
def __init__(self):
self.arguments = {
'batch_size': 64,
'epochs': 100,
'learning_rate': 1e-3,
'learning_rate_decay': 0,
'units': 128,
'drop_out_rate': 0.2,
'checkpoint_path': 'best_bilstm_model.hdf5',
'early_stop_patience': 10,
}
print('Building CNN_Generator Models...')
 print(self.arguments)
 def fit(self, train_gen, valid_gen):
file_path = self.arguments['checkpoint_path']
check_point = ModelCheckpoint(file_path, monitor = "val_loss", verbose = 1,
save_best_only = True, mode = "min")
 ra_val = RocAucEvaluation(validation_data=(X_valid, y_valid), interval = 1)
 early_stop = EarlyStopping(monitor = "val_loss", mode = "min", patience = self.arguments['early_stop_patience'])
 inp = Input(shape=(28,28,1))
x = Conv2D(filters=20, kernel_size =(5, 5), activation="relu" )(inp)
 max_pool_x = MaxPooling2D(pool_size=(2,2))(x)
 y = Conv2D(filters=20, kernel_size =(5, 5), activation="relu" )(max_pool_x)
 max_pool_y = MaxPooling2D(pool_size=(2,2))(y)
 flat = Flatten()(max_pool_y)
 z = Dense(100, activation="relu" )(flat)
 z = Dropout(rate = self.arguments['drop_out_rate'] )(z)
 z = Dense(100, activation="relu" )(z)
 z = Dropout(rate = self.arguments['drop_out_rate'] )(z)
 output = Dense(10, activation="softmax" )(z)
 self.model = Model(inputs = inp, outputs = output)
 self.model.compile(loss = "categorical_crossentropy", optimizer = Adam(lr = self.arguments['learning_rate'],
decay = self.arguments['learning_rate_decay']), metrics = ["accuracy"])
 history = self.model.fit_generator(train_gen, epochs = self.arguments['epochs'],
steps_per_epoch = X_train.shape[0] // self.arguments['batch_size'],
validation_steps = X_train.shape[0] // self.arguments['batch_size'],
validation_data = valid_gen, verbose = 1, callbacks = [ra_val, check_point, early_stop])
 self.model = load_model(file_path)
 print('Finished Building CNN Model as class attribute class.model')
 return self
def predict(self, X, batch_size, verbose):
return self.model.predict(X, batch_size = batch_size, verbose = verbose )<choose_model_class>
set_rf_samples(20000 )
cnn_gen = CNN_Generator()
cnn_gen.fit(train_gen, valid_gen)
 cnn_gen_pred = cnn_gen.predict(X_valid, batch_size = cnn.arguments['batch_size'], verbose = 1 )<predict_on_test>
%%time
m = RandomForestRegressor(n_estimators=10, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
train_predictions = []
valid_predictions = []
test_predictions = []
for i in range(5):
cnn = CNN_Generator()
cnn.fit(train_gen, valid_gen)
 train_predictions += [cnn.predict(X_train, batch_size = cnn.arguments['batch_size'], verbose = 0)]
valid_predictions += [cnn.predict(X_valid, batch_size = cnn.arguments['batch_size'], verbose = 1)]
test_predictions += [cnn.predict(test.values.reshape(-1,28,28,1), batch_size = cnn.arguments['batch_size'], verbose = 1)]<compute_train_metric>
%%time
m = RandomForestRegressor(n_estimators=80, max_features=0.5, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
train_pred = np.concatenate(train_predictions, axis=1)
 valid_pred = np.concatenate(valid_predictions, axis=1)
 test_pred = np.concatenate(test_predictions, axis=1)
 svm = SVC(probability=True, gamma='scale' ).fit(train_pred, np.argmax(y_train, axis=1))
pred = svm.predict(valid_pred)
 print("val_acc: ", round(np.sum(pred == np.argmax(y_valid, axis=1)) /y_valid.shape[0], 4))
print("val_ROC-AUC: ", round(roc_auc_score(y_valid, svm.predict_proba(valid_pred)) , 6))<save_to_csv>
%%time
m = RandomForestRegressor(n_estimators=80, max_features=0.5, min_samples_leaf=3, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
sample_submission = pd.read_csv(".. /input/sample_submission.csv")
 sample_submission['Label'] = svm.predict(test_pred)
 sample_submission.head()
sample_submission.to_csv('submission.csv', index=False )<set_options>
%%time
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
MaxPool2D, ReLU)
 %matplotlib inline<load_from_csv>
%%time
reset_rf_samples()
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
print("Loading...")
 data_train = pd.read_csv(".. /input/train.csv")
 data_test = pd.read_csv(".. /input/test.csv")
 print("Done!" )<train_model>
gc.collect()
print("Training data: {} rows, {} columns.".format(data_train.shape[0], data_train.shape[1]))
print("Test data: {} rows, {} columns.".format(data_test.shape[0], data_test.shape[1]))<prepare_x_and_y>
fi = rf_feat_importance(m, df); fi
x_train = data_train.values[:, 1:]
y_train = data_train.values[:, 0]<categorify>
%%time
reset_rf_samples()
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
def convert_2d(x):

 if len(x.shape)== 1:
m = 1
height = width = int(np.sqrt(x.shape[0]))
else:
m = x.shape[0]
height = width = int(np.sqrt(x.shape[1]))
x_2d = np.reshape(x,(m, height, width, 1))
return x_2d<categorify>
def get_oob(X):
set_rf_samples(20000)
 m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1, oob_score=True)
 m.fit(X, y_train)
 return m.oob_score_
def translate(x, y, dist):

 images = convert_2d(x)
 m, height, width, channel = images.shape
anchors = []
anchors.append(( 0, height, int(dist * width), width, 0, height, 0, width - int(dist * width)))
 anchors.append(( 0, height, 0, width - int(dist * width), 0, height, int(dist * width), width))
anchors.append(( int(dist * height), height, 0, width, 0, height - int(dist * height), 0, width))
anchors.append(( 0, height - int(dist * height), 0, width, int(dist * height), height, 0, width))
new_images = np.zeros(( 4, m, height, width, channel))
for i in range(4):
top, bottom, left, right, new_top, new_bottom, new_left, new_right = anchors[i]
new_images[i, :, new_top:new_bottom, new_left:new_right, :] = images[:, top:bottom, left:right, :]
new_images = np.reshape(new_images,(4 * m, -1))
y = np.tile(y,(4, 1)).reshape(( -1, 1))
new_images = np.concatenate(( y, new_images), axis=1 ).astype(int)
 return new_images<categorify>
cols = ["numGroups","killPoints","winPoints","killStreaks","kills","longestKill"]
def add_noise(x, y, noise_lvl):

 m, n = x.shape
noise_num = int(noise_lvl * n)
 for i in range(m):
noise_idx = np.random.randint(0, n, n ).argsort() [:noise_num]
x[i, noise_idx] = np.random.randint(0, 255, noise_num)
 noisy_data = np.concatenate(( y.reshape(( -1, 1)) , x), axis=1 ).astype("int")
 return noisy_data<normalization>
for col in cols:
print(col, get_oob(X_train.drop(labels=col, axis=1)) )
start = time.clock()
print("Augment the data...")
 cropped_imgs = crop_image(x_train, y_train, 0.9)
 translated_imgs = translate(x_train, y_train, 0.1)
 noisy_imgs = add_noise(x_train, y_train, 0.1)
 rotated_imgs = rotate_image(x_train, y_train, 10)
 data_train = np.vstack(( data_train, cropped_imgs, translated_imgs, noisy_imgs, rotated_imgs))
np.random.shuffle(data_train)
 print("Done!")
 time_used = int(time.clock() - start)
 print("Time used: {}s.".format(time_used))<prepare_x_and_y>
cols = ["killPoints","longestKill"]
x_train = data_train[:, 1:]
y_train = data_train[:, 0]
x_test = data_test.values
print("Augmented training data: {} rows, {} columns.".format(data_train.shape[0], data_train.shape[1]))<data_type_conversions>
get_oob(X_train.drop(labels=cols, axis=1))
x_train = convert_2d(x_train)
 x_test = convert_2d(x_test )<concatenate>
np.save(f'{PATH_TMP}features_keep.npy', np.array(X_train.columns))
num_classes = 10
y_train = keras.utils.to_categorical(y_train, num_classes )<feature_engineering>
features_keep = np.load(f'{PATH_TMP}features_keep.npy' )
x_train = x_train / 255
x_test = x_test / 255<split>
%%time
reset_rf_samples()
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
seed = np.random.randint(1, 100)
 x_train, x_dev, y_train, y_dev = train_test_split(x_train, y_train, test_size=0.1, random_state=seed )<set_options>
df, y, _ = proc_df(df_raw, 'winPlacePerc', skip_flds=["Id","groupId","matchId"] )
del data_train
del data_test
gc.collect()<choose_model_class>
df = df[features_keep].copy()
filters =(32, 32, 64, 64)
 kernel =(5, 5)
 drop_prob = 0.2
model = keras.models.Sequential()
model.add(Conv2D(filters[0], kernel, padding="same", input_shape=(28, 28, 1),
kernel_initializer=keras.initializers.he_normal()))
model.add(BatchNormalization())
 model.add(ReLU())
 model.add(Conv2D(filters[0], kernel, padding="same",
kernel_initializer=keras.initializers.he_normal()))
model.add(BatchNormalization())
 model.add(ReLU())
 model.add(MaxPool2D())
 model.add(Dropout(drop_prob))
model.add(Conv2D(filters[1], kernel, padding="same",
kernel_initializer=keras.initializers.he_normal()))
model.add(BatchNormalization())
 model.add(ReLU())
 model.add(MaxPool2D())
 model.add(Dropout(drop_prob))
model.add(Conv2D(filters[2], kernel, padding="same",
kernel_initializer=keras.initializers.he_normal()))
model.add(BatchNormalization())
 model.add(ReLU())
 model.add(MaxPool2D())
 model.add(Dropout(drop_prob))
model.add(Conv2D(filters[3], kernel, padding="same",
kernel_initializer=keras.initializers.he_normal()))
model.add(BatchNormalization())
 model.add(ReLU())
 model.add(MaxPool2D())
 model.add(Dropout(drop_prob))
model.add(Flatten())
 model.add(Dropout(drop_prob))
model.add(Dense(128, activation="relu"))
model.add(Dropout(drop_prob))
model.add(Dense(num_classes, activation="softmax"))
model.compile(keras.optimizers.Adam() , "categorical_crossentropy", metrics=["accuracy"] )<define_variables>
df_test = df_test[features_keep].copy()
iters = 100
batch_size = 1024<choose_model_class>
X_train, X_valid, y_train, y_valid = train_test_split(df, y, test_size=0.2)
 print(X_train.shape, X_valid.shape, y_train.shape, y_valid.shape )
lr_decay = ReduceLROnPlateau(monitor="val_acc", factor=0.5, patience=3, verbose=1, min_lr=1e-5 )<choose_model_class>
%%time
reset_rf_samples()
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1)
 m.fit(X_train, y_train)
 print_score(m )
<train_model><EOS> 
submission = pd.DataFrame({"Id": ids, "winPlacePerc": preds})
 submission.to_csv(f'{PATH_WORKING}submission.csv', index=False )