<jupyter_start><jupyter_text>Digit OCR based on MNIST DatasetUsing Neural Network model.<jupyter_code>import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import seaborn as sns
#Loading mnist dataset
(X_train, y_train) , (X_test, y_test) = keras.datasets.mnist.load_data()
len(X_train)
plt.matshow(X_train[0])
y_train[0]
X_train.shape
#Normalization
X_train = X_train / 255
X_test = X_test / 255
#Developing the Model
from tensorflow.keras import regularizers
model = tf.keras.Sequential([
                             
                  keras.layers.Flatten(input_shape=(28,28)),
                  keras.layers.Dense(300, activation = "relu"),
                  tf.keras.layers.Dropout(0.25),
                  keras.layers.Dense(60, activation = "relu"),
                  tf.keras.layers.Dropout(0.25),
                  keras.layers.Dense(10, activation = "sigmoid")
])
model.compile(
    optimizer = 'SGD', 
    loss = 'sparse_categorical_crossentropy',
    metrics = 'accuracy'
    )
model.summary()
history = model.fit(X_train, y_train, epochs=15, validation_split=0.1)
plt.title('Learning Curves')
plt.xlabel('Epoch')
plt.ylabel('Cross Entropy')
plt.plot(history.history['accuracy'], label='train')
plt.plot(history.history['val_accuracy'], label='val')
plt.legend()
plt.show()
model.evaluate(X_test, y_test)
y_predicted = model.predict(X_test)
y_predicted_labels = [np.argmax(i) for i in y_predicted]
conf_matrix = tf.math.confusion_matrix(labels=y_test,predictions=y_predicted_labels)

plt.figure(figsize = (10,8))
sns.heatmap(conf_matrix, annot=True, fmt='d')
plt.xlabel('Predcited')
plt.ylabel('Truths')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1282798833819242, 'fraction_numerical': 0.018658892128279883, 'mean_word_length': 4.061946902654867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '357849', 'license': 'MIT', 'n_tokens_mistral': 648, 'n_tokens_neox': 604, 'n_words': 113, 'path': 'digit_recog.ipynb', 'repo_name': 'ayanch07/MNIST-Digit_Recognition', 'size': '1715'}