text_plain_output_1.png
import matplotlib.pyplot as plt

import tensorflow as tf

X = X.reshape(X.shape[0], 28, 28)
X = X / 255.0

import matplotlib.pyplot as plt
fig = plt.gcf()
fig.set_size_inches(9, 9)
for i, img in enumerate(X):
    if i + 1 > 3 * 3:
        break

model = tf.keras.Sequential([tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(64, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax')])
model.compile(metrics=['acc'], optimizer='adam', loss='sparse_categorical_crossentropy')

model.summary()

history = model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=100)

acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))
plt.plot(epochs, acc)
plt.plot(epochs, val_acc)
plt.title('Training and validation accuracy')
plt.figure()
plt.plot(epochs, loss)
plt.plot(epochs, val_loss)
plt.title('Training and validation loss')