# ---
# 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
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/Akshatpattiwar512/Machine-Learning/blob/main/Keras_fashion_mnist.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + colab={"base_uri": "https://localhost:8080/"} id="igWtg6Sxawjr" outputId="1d39dd9b-0921-4b29-9f95-3f6e8f5458f0"
#Importing mnist dataset
# !pip install keras
from keras.datasets import fashion_mnist
data=fashion_mnist.load_data()

# + id="cJ73T4blb2nw"
(X_train,y_train), (X_test, y_test)=fashion_mnist.load_data()

# + id="epelJDVbgcKA"
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import  Input, Dense
import numpy as np

# + id="WwwdlesQkp-n"
x=np.array([[0,0], [0,1],[1,0], [1,1]],"uint8")
y=np.array([[0],[0],[0],[1]],"uint8")

# + colab={"base_uri": "https://localhost:8080/"} id="Q3yQykwql_Wd" outputId="c0baca1b-37c2-4695-f58c-cf011cb22969"
model=Sequential()
model.add(Dense(units=1,activation="sigmoid",input_dim=2))
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
model.summary()

# + colab={"base_uri": "https://localhost:8080/"} id="yRF0sbk-l1cO" outputId="0cc7cfcc-e852-4e12-c327-dd33c838b7c1"
model.fit(x,y,epochs=1000)

# + colab={"base_uri": "https://localhost:8080/"} id="cUw7H19Fq0z3" outputId="3f82321a-fa02-483f-dbc1-92eceb872e7c"
X_train[0].shape

# + id="zg2AKc14q8-Y"
X_train=X_train.reshape((X_train.shape[0],28*28)).astype('float32')
X_test=X_test.reshape((X_test.shape[0], 28*28)).astype('float32')

# + id="yGbHC0GorWGN"
#Normalizing values from 0-255 to 0-1
X_train=X_train/255
X_test=X_test/255

# + colab={"base_uri": "https://localhost:8080/"} id="4HHMnTY7veOT" outputId="3ba75433-a7da-4d49-e999-655ff8f7eb15"
from keras.utils import np_utils
y_train=np_utils.to_categorical(y_train)
y_test=np_utils.to_categorical(y_test)
num_classes=y_test.shape[1]
num_classes

# + id="E_jY7lLNwEth"
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout

# + id="Mfvn3s0Ywt08"
model=Sequential()
model.add(Dense(32,input_dim=28*28,activation='relu')) #hidden layer 1
model.add(Dense(64,activation='relu'))                 #hidden layer 2
model.add(Dense(128,activation='relu'))                #hidden layer 3
model.add(Dense(256,activation='relu'))                #hidden layer 4
model.add(Dense(512,activation='relu'))                #hidden layer 5
model.add(Dense(10,activation='softmax'))

# + id="Or6-mEVZxYaz"
model.compile(loss="categorical_crossentropy",optimizer='adam',metrics=['accuracy'])

# + colab={"base_uri": "https://localhost:8080/"} id="-NOMJV7kxvcB" outputId="7c331758-30c0-44a6-87e8-49814e4fc138"
model.summary()

# + colab={"base_uri": "https://localhost:8080/"} id="DjWxufsnxydR" outputId="e7172fd8-2e08-4664-c056-2fddab004f80"
model.fit(X_train,y_train,epochs=10,batch_size=200)

# + colab={"base_uri": "https://localhost:8080/"} id="wDQO9Yfoy1Eu" outputId="b50dc84d-d49a-4988-f77e-cd3ca319385b"
scores=model.evaluate(X_test,y_test)
scores

StarcoderdataJupyterScriptsDedupFiltered