text_plain_output_1.png image_output_1.png
from keras.layers import Conv2D,MaxPool2D,AveragePooling2D,Flatten,Dense,Input

from keras.losses import categorical_crossentropy,sparse_categorical_crossentropy

from keras.models import Sequential

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

numbers_lables_data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
x_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')

y_train = numbers_lables_data[['label']]
x_train = numbers_lables_data.iloc[:, 1:]

x_train = np.array(x_train).reshape((x_train.shape[0], 28, 28, 1))
x_test = np.array(x_test).reshape((x_test.shape[0], 28, 28, 1))

x_train = x_train / 255
x_test = x_test / 255

model = Sequential()
model.add(Input((28, 28, 1)))
model.add(Conv2D(128, 3, activation='relu', padding='same'))
model.add(AveragePooling2D(2))
model.add(Conv2D(64, 3, activation='relu', padding='same'))
model.add(AveragePooling2D(2))
model.add(Conv2D(32, 3, activation='relu', padding='same'))
model.add(AveragePooling2D(2))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(10, activation='softmax'))

model.compile(optimizer='adam', loss=sparse_categorical_crossentropy, metrics=['accuracy'])
model.summary()

model.fit(x_train, y_train, epochs=100, validation_split=0.1)