<jupyter_start><jupyter_text>Intermediate Net in Keras  Build a intermediate neural network in to classify MNIST digits  Set seed for reproducibility<jupyter_code>import numpy as np
np.random.seed(42)<jupyter_output><empty_output><jupyter_text>Load dependencies<jupyter_code>import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD<jupyter_output>Using TensorFlow backend.<jupyter_text>Load dataset<jupyter_code>(X_train, y_train), (X_test, y_test) = mnist.load_data()<jupyter_output><empty_output><jupyter_text>Preprocess data<jupyter_code>X_train = X_train.reshape(60000, 784).astype("float32")
X_test = X_test.reshape(10000, 784).astype("float32")
X_train /= 255
X_test /= 255
n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes)<jupyter_output><empty_output><jupyter_text>Design neural network<jupyter_code>model = Sequential()
model.add(Dense((64), activation='relu', input_shape=(784, )))
model.add(Dense((64), activation='relu'))
model.add(Dense((10), activation='softmax'))
model.summary()
model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.1), metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Train the model<jupyter_code>model.fit(X_train, y_train, batch_size=128, epochs=5, verbose=1, validation_data=(X_test, y_test))<jupyter_output>Train on 60000 samples, validate on 10000 samples
Epoch 1/5
60000/60000 [==============================] - 3s 46us/step - loss: 7.2508 - acc: 0.4717 - val_loss: 12.6553 - val_acc: 0.2134
Epoch 2/5
60000/60000 [==============================] - 2s 40us/step - loss: 12.6491 - acc: 0.2139 - val_loss: 12.6484 - val_acc: 0.2143
Epoch 3/5
60000/60000 [==============================] - 3s 44us/step - loss: 12.6406 - acc: 0.2147 - val_loss: 12.6791 - val_acc: 0.2112
Epoch 4/5
60000/60000 [==============================] - 2s 40us/step - loss: 12.6465 - acc: 0.2145 - val_loss: 12.6467 - val_acc: 0.2146
Epoch 5/5
60000/60000 [==============================] - 3s 42us/step - loss: 12.6412 - acc: 0.2150 - val_loss: 12.6485 - val_acc: 0.2146
{'fraction_non_alphanumeric': 0.19338539274230593, 'fraction_numerical': 0.11024345429490125, 'mean_word_length': 6.615384615384615, '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': '647432', 'license': 'Apache-2.0', 'n_tokens_mistral': 990, 'n_tokens_neox': 811, 'n_words': 159, 'path': 'Deep Learning/Tutorials/Intermediate_net_in_keras.ipynb', 'repo_name': 'surajch77/ML-Examples', 'size': '2177'}