Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<compute_test_metric>
tpu = tf.distribute.cluster_resolver.TPUClusterResolver.connect()
tpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)
print("The CV score is %.5f" % np.mean(CV_score_array,axis=0)) 
<save_to_csv>
train_dataframe=pd.read_csv(".. /input/digit-recognizer/train.csv")
 test_dataframe=pd.read_csv(".. /input/digit-recognizer/test.csv" )
submission.iloc[:,0:] = predictions
submission.to_csv('submission.csv' )<import_modules>
train_dataframe['label'].value_counts()
from catboost import CatBoostRegressor<load_from_csv>
train_label = train_dataframe.label.to_numpy()
train_image=train_dataframe.to_numpy() [0:,1:].reshape(42000,28,28,1)
 test_image = test_dataframe.to_numpy().reshape(28000,28,28,1 )
df_train = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/train.csv')
 y = df_train['target']
df_train.drop(['id', 'target'], axis = 1, inplace = True)
 df_test = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/test.csv')
 sub_id = df_test['id']
df_test.drop('id', axis = 1, inplace = True )<train_on_grid>
train_image = train_image.astype(float)/ 255.0
test_image = test_image.astype(float)/ 255.0
cbr = CatBoostRegressor()
cbr.fit(df_train, y )<prepare_output>
with tpu_strategy.scope() :
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64,(3,3), activation='relu',padding = 'Same', input_shape=(28, 28, 1)) ,
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Conv2D(128,(3,3), activation='relu',padding = 'Same'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Conv2D(256,(3,3), activation='relu',padding = 'Same'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Flatten() ,
tf.keras.layers.Dense(1024, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(10, activation='softmax')
 ])
 optimizer = Adam(learning_rate=0.001)
 model.compile(loss=SparseCategoricalCrossentropy(from_logits=True),
optimizer = optimizer,
metrics=['accuracy'])
 epochs = 50
batch_size = 16
submission = pd.DataFrame(sub_id, columns = ['id'])
 submission.head()<predict_on_test>
x_train,x_val,y_train,y_val=train_test_split(train_image,train_label,test_size=0.2,random_state=42 )
submission['target'] = cbr.predict(df_test )<save_to_csv>
history = model.fit(x_train,y_train,batch_size=64,epochs=15,validation_data=(x_val,y_val),shuffle=True )
submission.to_csv('catboost.csv', index = False )<set_options>
val_pred = model.predict(x_val )
mpl.rcParams['agg.path.chunksize'] = 10000<load_from_csv>
val_pred1 = np.argmax(val_pred, axis=1 )
train_data = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/train.csv')
 test_data = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/test.csv')
 print("successfully loaded!" )<filter>
predictions = model.predict(test_image )
outlier = train_data.loc[train_data.target < 1.0]
print(outlier )<drop_column>
submission = pd.DataFrame({'ImageId' : range(1,28001), 'Label' : list(subs)})
 submission.head(10)
 submission.shape
<prepare_x_and_y><EOS> 
submission.to_csv("submission1.csv", index = False )