<jupyter_start><jupyter_text>Simple MultiLayer Perceptron for multi-class classification<jupyter_code>import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import RMSprop
import numpy as np

batch_size = 128
num_classes = 10
epochs = 15<jupyter_output>Using TensorFlow backend.<jupyter_text>import Preprocess Data<jupyter_code>x_train = np.load("input_data/x_train_raw.npy")
y_train = np.load("input_data/y_train_raw.npy")
x_test = np.load("input_data/x_test_raw.npy")
y_test = np.load("input_data/y_test_raw.npy")<jupyter_output><empty_output><jupyter_text>Simple MLP Architecture<jupyter_code>model = Sequential()

model.add(Dense(256, activation='relu', input_shape=(784,)))
model.add(Dropout(0.3))

model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))

model.add(Dense(num_classes, activation='sigmoid'))

model.summary()
model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Training the model<jupyter_code>history = model.fit(x_train, y_train,
                    batch_size=batch_size,
                    epochs=epochs,
                    verbose=1,
                    validation_data=(x_test, y_test))<jupyter_output>Train on 60000 samples, validate on 10000 samples
Epoch 1/15
60000/60000 [==============================] - 7s 121us/step - loss: 0.3699 - acc: 0.8911 - val_loss: 0.1380 - val_acc: 0.9557
Epoch 2/15
60000/60000 [==============================] - 7s 109us/step - loss: 0.1539 - acc: 0.9523 - val_loss: 0.1035 - val_acc: 0.9676
Epoch 3/15
60000/60000 [==============================] - 7s 109us/step - loss: 0.1113 - acc: 0.9651 - val_loss: 0.0947 - val_acc: 0.9706
Epoch 4/15
60000/60000 [==============================] - 7s 109us/step - loss: 0.0885 - acc: 0.9720 - val_loss: 0.0828 - val_acc: 0.9738
Epoch 5/15
60000/60000 [==============================] - 7s 108us/step - loss: 0.0721 - acc: 0.9771 - val_loss: 0.0845 - val_acc: 0.9742
Epoch 6/15
60000/60000 [==============================] - 7s 110us/step - loss: 0.0642 - acc: 0.9799 - val_loss: 0.0890 - val_acc: 0.9739
Epoch 7/15
60000/60000 [==============================] - 7s 110us/step - loss: 0.0552 - acc: 0.9824 - val_loss: 0.0941 - [...]<jupyter_text>checking model accuracy and loss<jupyter_code>#checking model loss and accuracy
hdata = history.history 

from matplotlib import pyplot as plt
%matplotlib inline

plt.figure(0)
plt.plot(hdata['loss'],'r')
plt.plot(hdata['val_loss'],'g')

plt.figure(1)
plt.plot(hdata['acc'],'r')
plt.plot(hdata['val_acc'],'g')

plt.show()
#constructing confusion matrix:
from sklearn.metrics import confusion_matrix

prediction = model.predict(x_test)
y_prediction=np.array([np.argmax(prediction[i]) for i in range(10000)])
y_test = np.array([np.argmax(y_test[i]) for i in range(10000)])

cm = confusion_matrix(y_test, y_prediction)
cm<jupyter_output><empty_output><jupyter_text>Since the model is giving good result on both testing and training set  we will save this model and we will use it while deploying<jupyter_code>#saving model
model.save('trained_model/digit_classifier_mlp_1.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18673218673218672, 'fraction_numerical': 0.09183046683046683, 'mean_word_length': 4.932604735883425, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '151487', 'license': 'MIT', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1175, 'n_words': 242, 'path': 'training/MLP/Train_N_Save_Model.ipynb', 'repo_name': 'Mohit-Nathrani/digit-classifier', 'size': '3256'}