Kaggle competition: Kannada MNIST
<SOS> metric: CategorizationAccuracy Kaggle data source: kannada-mnist<drop_column>
import csv
import numpy as np
import keras
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense,Dropout,Activation,BatchNormalization
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import ReduceLROnPlateau, EarlyStopping
from keras import layers,regularizers
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from keras.optimizers import Adam,RMSprop
train_data.drop('Trim',inplace=True,axis=1)
 test_data.drop('Trim',inplace=True,axis=1 )<count_values>
decay=1e-4
xtrain = []
ytrain = []
xtest = []
xval = []
yval = []
train_data['SubModel'].value_counts()<drop_column>
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
train =pd.read_csv(os.path.join(dirname,'train.csv'))
print("train",np.shape(train))
test =pd.read_csv(os.path.join(dirname,'test.csv'))
print("test",np.shape(test))
sample_submission =pd.read_csv(os.path.join(dirname,'sample_submission.csv'))
Dig_MNIST=pd.read_csv(os.path.join(dirname,'Dig-MNIST.csv'))
xtrain=train.drop('label',axis=1)
 ytrain=train.label
xtest = test.drop('id', axis = 1)
 xval=Dig_MNIST.drop('label',axis=1)
 yval=Dig_MNIST.label
xtrain=xtrain.values
xtest=xtest.values
xval=xval.values
ytrain=ytrain.values
yval=yval.values
train_data.drop('SubModel',inplace=True,axis=1)
 test_data.drop('SubModel',inplace=True,axis=1 )<count_values>
xtrain=xtrain.reshape(-1,28,28,1 ).astype('float32')
 xtest=xtest.reshape(-1,28,28,1 ).astype('float32')
 xval=xval.reshape(-1,28,28,1 ).astype('float32')
 xtrain=(xtrain-np.mean(xtrain)) /255
xtest=(xtest-np.mean(xtest)) /255
xval=(xval-np.mean(xval)) /255
train_data['Color'].value_counts()<count_values>
model=Sequential()
model.add(layers.Conv2D(64,(3,3), padding='same', input_shape=(28, 28, 1)))
 model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.Conv2D(64,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.Conv2D(64,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.MaxPooling2D(2, 2))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(128,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.Conv2D(128,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.Conv2D(128,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.MaxPooling2D(2,2))
model.add(layers.Dropout(0.2))
model.add(layers.Conv2D(256,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.Conv2D(256,(3,3), padding='same'))
model.add(layers.BatchNormalization(momentum=0.9, epsilon=1e-5, gamma_initializer="uniform"))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.MaxPooling2D(2,2))
model.add(layers.Dropout(0.4))
model.add(layers.Flatten())
 model.add(layers.Dense(256))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.BatchNormalization())
 model.add(layers.Dense(256))
model.add(layers.LeakyReLU(alpha=0.1))
model.add(layers.BatchNormalization())
 model.add(layers.Dense(10, activation='softmax'))
test_data['Color'].value_counts()<data_type_conversions>
optimizer = RMSprop(learning_rate=0.002,rho=0.9)
 model.compile(optimizer=optimizer,loss='sparse_categorical_crossentropy',metrics=['accuracy'] )
train_data['Color'].fillna(value='Color_Unknown',inplace=True)
 test_data['Color'].fillna(value='Color_Unknown',inplace=True )<count_missing_values>
datagen = ImageDataGenerator(
 rotation_range=11,
zoom_range=0.4,
width_shift_range=0.3,
height_shift_range=0.3, 
)
 datagen.fit(xtrain )
print("Number of null values in Color column "+str(train_data['Color'].isnull().sum()))
print("Number of null values in Color column "+str(test_data['Color'].isnull().sum()))<count_values>
learning_rate_reduction = tf.keras.callbacks.ReduceLROnPlateau(
 monitor='loss',
factor=0.2,
patience=2,
verbose=1,
mode="auto",
min_delta=0.0001,
cooldown=0,
min_lr=0.00001 
)
 es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=300, restore_best_weights=True )
train_data['Transmission'].value_counts()<count_values>
history=model.fit_generator(datagen.flow(xtrain, ytrain, batch_size=1024),
steps_per_epoch=len(xtrain)//1024,
epochs=50,
validation_data=(np.array(xval),np.array(yval)) ,
validation_steps=50,
callbacks=[learning_rate_reduction, es])
test_data['Transmission'].value_counts()<filter>
ytest = model.predict_classes(xtest)
 id_col = np.arange(ytest.shape[0])
 submission = pd.DataFrame({'id': id_col, 'label': ytest})
 submission.to_csv('submission.csv', index = False )