text_plain_output_1.png
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D

from keras.models import Sequential

from keras.optimizers import RMSprop

import keras

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

test = pd.read_csv('../input/test.csv')
train = pd.read_csv('../input/train.csv')

y_train = train['label']

x_train = train.drop(labels=['label'], axis=1)

y_train.value_counts()

x_train = x_train / 255.0
test = test / 255.0

x_train = x_train.values.reshape(-1, 28, 28, 1)
test = test.values.reshape(-1, 28, 28, 1)

y_train = keras.utils.to_categorical(y_train, num_classes=10)

model = Sequential()
model.add(Conv2D(32, (3, 3), padding='Same', activation='relu', input_shape=(28, 28, 1)))
model.add(Conv2D(64, (5, 5), activation='relu'))
model.add(MaxPool2D((2, 2)))
model.add(Conv2D(64, (3, 3), padding='Same', activation='relu'))
model.add(Dropout(0.25))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(Conv2D(24, (5, 5), padding='Same', activation='relu'))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(32, activation='relu'))
model.add(Dense(10, activation='softmax'))
model.summary()

optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0)
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])

history = model.fit(x_train, y_train, batch_size=128, epochs=10, verbose=1)

score = model.evaluate(x_val, y_val, verbose=1)
print('Test loss:', score[0])
print('Test accuracy:', score[1])