Kaggle competition: PUBG Finish Placement Prediction (Kernels Only)
y_pred = np.argmax(model.predict(X_test), axis=1 )<prepare_output>
result = pd.Series(y_pred, name="Label" ).to_frame().reset_index().rename(columns={"index": "ImageId"})
 result["ImageId"] += 1
result.head()<save_to_csv>
train = pd.get_dummies(train,columns=['matchType'] )
result.to_csv("out.csv", index=False )<set_options>
train =train.dropna()
%matplotlib inline 
<load_from_csv>
test = pd.get_dummies(test,columns=['matchType'] )
train_file = ".. /input/train.csv"
test_file = ".. /input/test.csv"
output_file = "submission.csv"
raw_data = np.loadtxt(train_file, skiprows=1, dtype='int', delimiter=',')
 x_train, y_train = raw_data[:, 1:], raw_data[:, 0]
x_train = x_train.reshape(-1, 28, 28, 1 ).astype("float32")/255
y_train = keras.utils.to_categorical(y_train )<choose_model_class>
y_train =train['winPlacePerc']
x_train =train.drop(['Id','groupId','matchId','winPlacePerc'],axis=1 )
model = keras.models.Sequential([
keras.layers.Conv2D(32, kernel_size=3, activation='relu',
input_shape=(28, 28, 1)) ,
keras.layers.BatchNormalization() ,
keras.layers.Conv2D(32, kernel_size=3, activation='relu'),
keras.layers.BatchNormalization() ,
keras.layers.Conv2D(32, kernel_size=5, strides=2, padding='same',
activation='relu'),
keras.layers.BatchNormalization() ,
keras.layers.Dropout(rate=0.4),
keras.layers.Conv2D(64, kernel_size=3, activation='relu'),
keras.layers.BatchNormalization() ,
keras.layers.Conv2D(64, kernel_size=3, activation='relu'),
keras.layers.BatchNormalization() ,
keras.layers.Conv2D(64, kernel_size=5, strides=2, padding='same',
activation='relu'),
keras.layers.BatchNormalization() ,
keras.layers.Dropout(rate=0.4),
keras.layers.Flatten() ,
keras.layers.Dense(128, activation='relu'),
keras.layers.BatchNormalization() ,
keras.layers.Dropout(rate=0.4),
keras.layers.Dense(10, activation='softmax')
 ])
 model.compile(loss='categorical_crossentropy', optimizer='nadam', metrics=["accuracy"] )<prepare_x_and_y>
X_train = x_train.values
Y_train = y_train.values
def elastic_transform(image, alpha_range, sigma, random_state=None):
random_state = np.random.RandomState(random_state)
 if np.isscalar(alpha_range):
alpha = alpha_range
else:
alpha = np.random.uniform(low=alpha_range[0], high=alpha_range[1])
 shape = image.shape
dx = gaussian_filter(random_state.rand(*shape)* 2 - 1, sigma)* alpha
dy = gaussian_filter(random_state.rand(*shape)* 2 - 1, sigma)* alpha
x, y, z = np.meshgrid(np.arange(shape[0]),
np.arange(shape[1]),
np.arange(shape[2]), indexing='ij')
 indices =(np.reshape(x + dx,(-1, 1)) ,
np.reshape(y + dy,(-1, 1)) ,
np.reshape(z,(-1, 1)))
 return map_coordinates(image, indices, order=1, mode='reflect' ).reshape(shape )<train_model>
validation_size = 0.20
seed = 1000
X_train, X_valid, Y_train, Y_valid = train_test_split(X_train, Y_train, test_size=validation_size, random_state=seed )
datagen = keras.preprocessing.image.ImageDataGenerator(
 zoom_range=0.0,
height_shift_range=2,
width_shift_range=2,
preprocessing_function=lambda x: elastic_transform(x, alpha_range=[8, 10], sigma=3))
datagen.fit(x_train )<train_model>
train_data = lgb.Dataset(data=X_train, label=Y_train)
 valid_data = lgb.Dataset(data=X_valid, label=Y_valid)
 params = {
'num_leaves': 144,
"metric" : "mae",
'learning_rate': 0.1,
'n_estimators': 800,
'max_depth':13,
'max_bin':55,
'bagging_fraction':0.8,
'bagging_freq':5,
'feature_fraction':0.9
}
lgb_model = lgb.train(params, train_data, valid_sets=[train_data, valid_data], verbose_eval=1000 )
batch_size = 32
epochs = 30
learning_rate_reduction = keras.callbacks.ReduceLROnPlateau(monitor='val_acc', patience=3, verbose=1, factor=0.5, min_lr=0.00001)
 model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size),
epochs=epochs, verbose=2,
callbacks=[learning_rate_reduction],
steps_per_epoch=x_train.shape[0] // batch_size )<data_type_conversions>
X_test = test.drop(["Id", "groupId", "matchId"], axis = 1 )
<save_to_csv><EOS> 
Y_test = lgb_model.predict(X_test)
 submission = pd.DataFrame({
"Id": test['Id'],
"winPlacePerc": Y_test
})
 submission.to_csv('sample_submission_20181124_v1.csv', index=False )