import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.utils import to_categorical
import numpy as np
import matplotlib.pyplot as plt
tf.random.set_seed(7)
mnist = keras.datasets.mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()
from tensorflow.keras.utils import to_categorical
mean = np.mean(X_train)
stddev = np.std(X_train)
X_train = (X_train - mean)/stddev
X_test = (X_test - mean)/stddev
y_train = to_categorical(y_train, num_classes=10)
y_test = to_categorical(y_test, num_classes=10)
init = keras.initializers.RandomUniform(minval=-0.1, maxval=0.1)
X_train.shape
y_train.shape
y_test.shape
from tensorflow.keras import layers
EPOCHS = 20
model = keras.Sequential([
layers.Flatten(input_shape=(28,28)),
layers.Dense(25, activation = 'tanh', kernel_initializer = init, bias_initializer = 'zeros'),
layers.Dense(10, activation = 'sigmoid', kernel_initializer = init, bias_initializer = 'zeros')
])
optimizer = keras.optimizers.SGD(learning_rate=0.01)
model.compile(loss=tf.keras.losses.mean_squared_error, metrics=['accuracy'], optimizer = optimizer)
history = model.fit(X_train, y_train, validation_data = (X_test, y_test), epochs = EPOCHS, batch_size=1, verbose = 2, shuffle= True)