<jupyter_start><jupyter_text>Classify MNIST digits using CNN<jupyter_code>import keras
from keras.models import Sequential
from keras.layers import Dense, Flatten, Dropout
from keras.layers import Conv2D,MaxPooling2D
from keras.callbacks import ModelCheckpoint
import os
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)
from matplotlib import pyplot
from scipy.misc import toimage
pyplot.imshow(toimage(x_train[4]))
pyplot.show()
x_train=x_train.reshape(60000,28,28,1).astype('float32')
x_test=x_test.reshape(10000,28,28,1).astype('float32')
x_train /= 255
x_test /= 255
n_class=10
y_train = keras.utils.to_categorical(y_train,n_class)
y_test = keras.utils.to_categorical(y_test,n_class)
n_conv = 64
k_conv = (3,3)

model = Sequential()
model.add(Conv2D(n_conv,k_conv, activation='relu'))
model.add(MaxPooling2D())
model.add(Flatten())
model.add(Dense(64,activation='tanh'))
model.add(Dense(10,activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train,y_train,epochs=10,verbose=1, validation_data=(x_test,y_test))<jupyter_output>Train on 60000 samples, validate on 10000 samples
Epoch 1/10
60000/60000 [==============================] - 142s 2ms/step - loss: 0.1411 - acc: 0.9593 - val_loss: 0.0636 - val_acc: 0.9798
Epoch 2/10
60000/60000 [==============================] - 92s 2ms/step - loss: 0.0493 - acc: 0.9855 - val_loss: 0.0457 - val_acc: 0.9844
Epoch 3/10
60000/60000 [==============================] - 92s 2ms/step - loss: 0.0306 - acc: 0.9911 - val_loss: 0.0424 - val_acc: 0.9859
Epoch 4/10
60000/60000 [==============================] - 87s 1ms/step - loss: 0.0200 - acc: 0.9943 - val_loss: 0.0445 - val_acc: 0.9856
Epoch 5/10
60000/60000 [==============================] - 85s 1ms/step - loss: 0.0128 - acc: 0.9964 - val_loss: 0.0457 - val_acc: 0.9856
Epoch 6/10
60000/60000 [==============================] - 89s 1ms/step - loss: 0.0077 - acc: 0.9980 - val_loss: 0.0397 - val_acc: 0.9879
Epoch 7/10
60000/60000 [==============================] - 87s 1ms/step - loss: 0.0055 - acc: 0.9988 - val_loss: 0.0474 - val_ac[...]
{'fraction_non_alphanumeric': 0.22721149528513696, 'fraction_numerical': 0.13740458015267176, 'mean_word_length': 5.5337243401759535, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '119615', 'license': 'FTL', 'n_tokens_mistral': 1087, 'n_tokens_neox': 869, 'n_words': 174, 'path': 'notebooks/NN - MNIST Image Classification - CNN.ipynb', 'repo_name': 'amrendra1002/ML-DL', 'size': '2227'}