Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<load_from_csv>
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_addons as tfa
import PIL
from sklearn.model_selection import train_test_split
main = pd.read_csv(dfk.iloc[20, 2])
 sub4 = generate(main, sub3, 0.60 )<compute_test_metric>
ROOT_DIR = '/kaggle/input/digit-recognizer'
train_df = pd.read_csv(os.path.join(ROOT_DIR, 'train.csv'))
test_df = pd.read_csv(os.path.join(ROOT_DIR, 'test.csv'))
sub4 = comparison(sub4, 17, 0.9955, 0.9985 )<load_from_csv>
feature_train = train_df.to_numpy() [:,1:]
label_train = train_df.to_numpy() [:,0]
feature_test = test_df.to_numpy()
original = pd.read_csv(".. /input/feb84186/FEB84186.csv")
 sub5 = comparison5(sub4, original, 18, 1.0000, 0.9960)
<save_to_csv>
feature_train, feature_val, label_train, label_val = train_test_split(feature_train, label_train, test_size=0.2, stratify=label_train )
sub = sub5
sub.to_csv("submission.csv", index=False)
 sub1.to_csv("submission1.csv", index=False)
 sub2.to_csv("submission2.csv", index=False)
 sub3.to_csv("submission3.csv", index=False)
 sub4.to_csv("submission4.csv", index=False)
 sub5.to_csv("submission5.csv", index=False)
 !ls<set_options>
print('Train size: {}, validation size: {}'.format(len(label_train), len(label_val)) )
optuna.logging.set_verbosity(optuna.logging.CRITICAL )<load_from_csv>
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
 rotation_range=25,
height_shift_range=3,
width_shift_range=3
)
data = pd.read_csv('.. /input/tabular-playground-series-feb-2021/train.csv', index_col=0)
 test = pd.read_csv('.. /input/tabular-playground-series-feb-2021/test.csv', index_col=0)
 preds = data.columns[:-1]
target = data.columns[-1]<data_type_conversions>
BATCH_SIZE = 64
train_ds = train_datagen.flow(feature_train, label_train, batch_size=BATCH_SIZE)
 val_ds = tf.data.Dataset.from_tensor_slices(( feature_val, label_val)).batch(BATCH_SIZE ).prefetch(1)
 test_ds = tf.data.Dataset.from_tensor_slices(feature_test ).batch(BATCH_SIZE ).prefetch(1 )
cat_cols = [col for col in preds if 'cat' in col]
data[cat_cols] = data[cat_cols].astype('category')
 test[cat_cols] = test[cat_cols].astype('category' )<train_model>
layers = [
tf.keras.layers.Conv2D(16, kernel_size=3, strides=1, padding='same', input_shape=(28,28,1)) ,
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.ReLU() ,
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Conv2D(32, kernel_size=3, strides=1, padding='valid'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.ReLU() ,
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Conv2D(64, kernel_size=5, strides=1, padding='valid'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.ReLU() ,
tf.keras.layers.Dropout(0.25),
tf.keras.layers.MaxPool2D(strides=2),
tf.keras.layers.Flatten() ,
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Dense(10, activation='softmax')
 ]
model = tf.keras.Sequential(layers=layers)
 lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(1e-3, decay_steps=3000, decay_rate=0.95)
 optimizer = tf.keras.optimizers.Adam(learning_rate=lr_schedule)
 model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])
 history = model.fit(train_ds, epochs=40, validation_data=val_ds )
<find_best_params><EOS> 
pred_test = np.argmax(model.predict(test_ds), axis=1)
 out_df = pd.DataFrame({'ImageId': np.arange(1, len(pred_test)+1), 'Label': pred_test})
 out_df.to_csv('output.csv', index=False )