text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import tensorflow as tf

import warnings

from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import pandas as pd
import tensorflow as tf
from tensorflow import keras
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt

train = pd.read_csv('../input/fashion-mnist_train.csv')

train.shape

test = pd.read_csv('../input/fashion-mnist_test.csv')

test.shape

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

train_images = train.iloc[:, 1:785]
train_labels = train.iloc[:, 0]
test_images = test.iloc[:, 1:785]
test_labels = test.iloc[:, 0]

plt.colorbar()
plt.xticks([])
plt.yticks([])

plt.colorbar()
plt.xticks([])
plt.yticks([])

train_images = train_images / 255.0
test_images = test_images / 255.0

for i in range(25):
    plt.xticks([])
    plt.yticks([])

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(64, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))

model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

train_images = train_images.values
train_labels = train_labels.values
test_images = test_images.values
test_labels = test_labels.values

model.fit(train_images, train_labels, epochs=10)

test_loss, test_acc = model.evaluate(test_images, test_labels)

predictions = model.predict(test_images)

np.argmax(predictions[0])