Kaggle competition: Digit Recognizer
model = CatBoostClassifier(iterations=1000,
learning_rate=1,
depth=2,
loss_function='MultiClass',
random_seed=1,
bagging_temperature=22,
od_type='Iter',
metric_period=100,
od_wait=100 )<train_model>
train_df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 print(train_df.shape )
model.fit(train_dataset, eval_set= eval_dataset, plot= True )<predict_on_test>
X_train = train_df.iloc[:,1:].values
y_train = train_df.iloc[:,0].values
preds_class = model.predict(eval_dataset)
 preds_proba = model.predict_proba(eval_dataset )<merge>
N = X_train.shape[0]
X_train = X_train.reshape(N,28,28,1)
 X_train = X_train.astype('float32')
 X_train /= 255.
 y_train = tf.one_hot(y_train, 10)
 X_train.shape, y_train.shape
test_1 = test.merge(severity_type, how = 'left', left_on='id', right_on='id')
 test_2 = test_1.merge(resource_type, how = 'left', left_on='id', right_on='id')
 test_3 = test_2.merge(log_failure, how = 'left', left_on='id', right_on='id')
 test_4 = test_3.merge(event_type, how = 'left', left_on='id', right_on='id' )<remove_duplicates>
def make_model(inputs):
x = tf.keras.layers.Conv2D(filters=32,kernel_size=(3,3))(inputs)
 x = tf.keras.layers.BatchNormalization()(x)
 x = tf.keras.layers.ReLU()(x)
 x = tf.keras.layers.MaxPool2D()(x)
 x = tf.keras.layers.Conv2D(filters=64,kernel_size=(3,3))(x)
 x = tf.keras.layers.BatchNormalization()(x)
 x = tf.keras.layers.ReLU()(x)
 x = tf.keras.layers.MaxPool2D()(x)
 x = tf.keras.layers.Conv2D(filters=1024,kernel_size=(5,5))(x)
 x = tf.keras.layers.BatchNormalization()(x)
 x = tf.keras.layers.ReLU()(x)
 x = tf.keras.layers.Conv2D(filters=256,kernel_size=(1,1))(x)
 x = tf.keras.layers.BatchNormalization()(x)
 x = tf.keras.layers.ReLU()(x)
 x = tf.keras.layers.Conv2D(filters=10,kernel_size=(1,1))(x)
 x = tf.keras.layers.BatchNormalization()(x)
 x = tf.keras.layers.Softmax()(x)
 x = tf.keras.layers.Reshape(( 10,))(x)
 return x
test_4.drop_duplicates(subset= 'id', keep= 'first', inplace = True)
 test_4.head()<count_missing_values>
tf.keras.backend.clear_session()
inputs = tf.keras.Input(shape=(28,28,1))
outputs = make_model(inputs)
 model = tf.keras.Model(
 inputs=inputs,
outputs=outputs,
name="simple" 
)
 model.compile(optimizer='adam', loss='categorical_crossentropy' )
test_4.isnull().sum()<save_to_csv>
history = model.fit(X_train,y_train, validation_split=0.2,epochs=10 )
predict_test=model.predict_proba(test_4)
 pred_df=pd.DataFrame(predict_test,columns=['predict_0', 'predict_1', 'predict_2'])
 submission_cat=pd.concat([test[['id']],pred_df],axis=1)
 submission_cat.to_csv('sub_cat_1.csv',index=False,header=True )<load_from_csv>
X_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv' ).values
N_test = X_test.shape[0]
X_test = X_test.reshape(N_test,28,28,1)
 X_test = X_test.astype('float32')
 X_test /= 255.
 X_test.shape
train = pd.read_csv(input_path / 'train.csv', index_col='id')
 test = pd.read_csv(input_path / 'test.csv', index_col='id')
 submission = pd.read_csv(input_path / 'sample_submission.csv', index_col='id' )<split>
pred = model.predict(X_test)
 pred.shape
<init_hyperparams><EOS> 
submissions=pd.DataFrame({"ImageId": list(range(1,len(pred)+1)) ,
"Label": np.argmax(pred, axis=1)})
 submissions.to_csv("my_submissions.csv", index=False, header=True )