Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<drop_column>
print(os.listdir(".. /input"))
seed = 4529
np.random.seed(seed )
df_train.drop('CompetitionDistance', inplace = True, axis = 1)
 df_train.head()<prepare_x_and_y>
base_dir = os.path.join(".. ", "input")
 train_df = pd.read_csv(os.path.join(base_dir, "train.csv"))
test_df = pd.read_csv(os.path.join(base_dir, "test.csv"))
len(train_df )
X = df_train.drop(['Sales', 'Store'], axis = 1)
 y = df_train['Sales']<split>
%load_ext tensorboard.notebook
%tensorboard --logdir logs
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= 0.1, random_state = 53)
 X_val, X_test, y_val, y_test = train_test_split(X_test, y_test, test_size = 0.5, random_state = 53 )<choose_model_class>
x = train_df.drop(['label'], axis=1 ).values
y = train_df['label'].values
test_x = test_df.values
%%time
xgbreg = xgb.XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,
importance_type='gain', interaction_constraints='',
learning_rate=0.3, max_delta_step=0, max_depth=6,
min_child_weight=1, monotone_constraints='() ',
n_estimators=3000, n_jobs=16, num_parallel_tree=1, random_state=0,
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, subsample=1,
tree_method='exact', validate_parameters=1, verbosity=None)
 xgbreg.fit(X_train, y_train )<predict_on_test>
x = x.reshape(-1, 28, 28, 1)
 x = x / 255.0
test_x = test_x.reshape(-1, 28, 28, 1)
 test_x = test_x / 255.0
y = to_categorical(y, num_classes=10)
 x_train, x_val, y_train, y_val = train_test_split(x, y, test_size = 0.1, random_state=seed )
y_train_pred = xgbreg.predict(X_train )<compute_test_metric>
model = Sequential([
Conv2D(128,(3,3), activation="relu", input_shape=(28, 28, 1)) ,
BatchNormalization() ,
Conv2D(128,(3,3), activation="relu"),
BatchNormalization() ,
MaxPooling2D(2,2),
Dropout(0.2),
Conv2D(64,(3,3), activation="relu"),
BatchNormalization() ,
Conv2D(64,(3,3), activation="relu"),
BatchNormalization() ,
MaxPooling2D(2,2),
Dropout(0.2),
Flatten() ,
Dense(units=256, activation='relu'),
Dropout(0.4),
Dense(units=256, activation='relu'),
Dropout(0.4),
Dense(units=10, activation='softmax')
 ])
 model.compile(optimizer=Adam(lr=0.001),
loss='categorical_crossentropy',
metrics=['acc'])
 model.summary()
r2_score(y_train, y_train_pred )<predict_on_test>
batch_size = 128
epochs = 30
datagen = ImageDataGenerator(rotation_range=15,
width_shift_range=0.2,
height_shift_range=0.2,
zoom_range=0.15,
shear_range=0.15)
 datagen.fit(x_train)
 history = model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size),
validation_data=(x_val, y_val),
steps_per_epoch = x_train.shape[0] // batch_size,
epochs=epochs, callbacks=callbacks)
<compute_test_metric><EOS> 
pred = model.predict(test_x)
 pred = np.argmax(pred, axis=1)
 pred = pd.Series(pred, name="Label")
 test_df = pd.concat([pd.Series(range(1,28001), name = "ImageId"), pred],axis = 1)
 test_df.to_csv('mnist-submission.csv', index = False )