# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="B2PEgedWRq3E" colab_type="code" outputId="1af35217-3bd9-4707-9c64-8613b0d446fd" colab={"base_uri": "https://localhost:8080/", "height": 87}
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import mnist
(xtrain,ytrain),(xtest,ytest)=mnist.load_data()
print(xtrain.shape)
print(ytrain.shape)
print(xtest.shape)
print(ytest.shape)

# + id="4xaQFO29SQ6X" colab_type="code" outputId="765cda62-a384-4025-ab0f-2af02cbb043c" colab={"base_uri": "https://localhost:8080/", "height": 265}
plt.imshow(xtrain[0],cmap='gray')
plt.show()

# + id="FnzzbehlSa9O" colab_type="code" outputId="3a118fde-92ed-481b-cad5-3b81a0a4f1a2" colab={"base_uri": "https://localhost:8080/", "height": 35}
ytrain[0]

# + id="eBj6xPoDThCV" colab_type="code" colab={}
# input neurons = 28x28 = 784
# output neurons = 10

# + id="ShkDMGhoTmMF" colab_type="code" outputId="a4ba8790-8a0f-4605-c2f0-f3b32e5acedd" colab={"base_uri": "https://localhost:8080/", "height": 52}
# onehot encoding the label
from tensorflow.keras.utils import to_categorical
ytrain = to_categorical(ytrain)
ytest = to_categorical(ytest)
print(ytrain.shape)
print(ytest.shape)

# + id="irIt0FzoUTEi" colab_type="code" colab={}
from tensorflow.keras import models,layers

# + id="J2YhsMBnVWgE" colab_type="code" colab={}
model = models.Sequential()
# add input layer - add a flatten layer >> 28x28 >> 1x784
model.add(layers.Flatten(input_shape=(28,28)))

# add a hidden layer
model.add(layers.Dense(100,activation='relu'))

# add a hidden layer
model.add(layers.Dense(50,activation='relu'))

# add output layer
model.add(layers.Dense(10,activation='softmax'))

# + id="TrIoK0bDXTLG" colab_type="code" outputId="a6bff629-b387-40ac-d12b-b8807b4154a2" colab={"base_uri": "https://localhost:8080/", "height": 424}
# compile - ANN
model.compile(loss='categorical_crossentropy',optimizer='adam',
              metrics=['accuracy'])
# Train  - ANN
model.fit(xtrain,ytrain,epochs=10,batch_size=1000,verbose=True,
          validation_data=(xtest,ytest))

# + id="tddfez4_aTZb" colab_type="code" outputId="85b61899-6268-4eff-aac7-2aaee86a7206" colab={"base_uri": "https://localhost:8080/", "height": 299}
model.summary()

# + id="8Cw7lMj1i0sO" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered