Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<compute_test_metric>
%matplotlib inline
np.random.seed(2)
 sns.set(style='white', context='notebook', palette='deep' )
mae = metrics.mean_absolute_error(y_val, y_val_pred)
 mse = metrics.mean_squared_error(y_val, y_val_pred)
 rmse = np.sqrt(metrics.mean_absolute_error(y_val, y_val_pred))
print("Mean Absolute Error")
 print(mae)
 print()
print("Mean Squared Error")
 print(mse)
 print()
print("Root Mean Squared Error")
 print(rmse )<compute_test_metric>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
evaluation = evaluation_df('Extreme Gradient Boosting with Change in Data', mae, mse, rmse, evaluation )<prepare_x_and_y>
X_train = X_train / 255.0
test = test / 255.0
X = df_train.drop(['Sales', 'Year'], axis = 1)
 y = df_train['Sales']<split>
Y_train = to_categorical(Y_train, num_classes = 10 )
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>
random_seed = 2
%%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=5,
min_child_weight=1, monotone_constraints='() ',
n_estimators=4500, 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_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.05, random_state=random_seed )
y_train_pred = xgbreg.predict(X_train )<compute_test_metric>
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2)))
 model.add(Dropout(0.25))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))
r2_score(y_train, y_train_pred )<predict_on_test>
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0 )
y_val_pred = xgbreg.predict(X_val )<compute_test_metric>
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )
r2_score(y_val, y_val_pred )<predict_on_test>
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001 )
y_test_pred = xgbreg.predict(X_test )<compute_test_metric>
epochs = 30
batch_size = 86
r2_score(y_test, y_test_pred )<compute_test_metric>
datagen = ImageDataGenerator(
 featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range = 0.1,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=False,
vertical_flip=False)
 datagen.fit(X_train )
mae = metrics.mean_absolute_error(y_val, y_val_pred)
 mse = metrics.mean_squared_error(y_val, y_val_pred)
 rmse = np.sqrt(metrics.mean_absolute_error(y_val, y_val_pred))
print("Mean Absolute Error")
 print(mae)
 print()
print("Mean Squared Error")
 print(mse)
 print()
print("Root Mean Squared Error")
 print(rmse )<compute_test_metric>
history = model.fit_generator(datagen.flow(X_train,Y_train, batch_size=batch_size),
epochs = epochs, validation_data =(X_val,Y_val),
verbose = 2, steps_per_epoch=X_train.shape[0] // batch_size
, callbacks=[learning_rate_reduction] )
evaluation = evaluation_df('Extreme Gradient Boosting with Change in Data and tuning', mae, mse, rmse, evaluation )<load_from_csv>
results = model.predict(test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label" )
df_test = pd.read_csv('.. /input/rossmann-store-sales/test.csv')
 df_test.head()<count_missing_values>
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("submission.csv",index=False )