โ“Machine Learning Fashion-MNIST ๐Ÿ‘—๐Ÿ‘–๐Ÿ‘•

# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment

responses = initialize_assignment("ML_practice_q", "week_9", "practicequiz", assignment_points = 20.0, assignment_tag = 'week9-practicequiz')

# Initialize Otter
import otter
grader = otter.Notebook("ML_practice_q.ipynb")

โ“Machine Learning Fashion-MNIST ๐Ÿ‘—๐Ÿ‘–๐Ÿ‘•#

You are presented with a dataset of 60,000 28x28 grayscale images of fashion items, with 10 categories. It is your job to build a classifier algorithm that can correctly classify a new image using scikit-learn. Your goal is to train a model that achieves at least 80% accuracy on the test set. We are going to provide you with a guide to help you visualize that data, however will not provide you with the code to train the model. You can use any algorithm you want to train the model as long as the model is assigned to a variable called model, and it has a .predict() method, that takes in a numpy array of images and returns a numpy array of predictions.

We are only going to grade the final model accuracy on a hidden test set. ๐ŸŽฏ

import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.datasets import fashion_mnist

# This is where you should import packages for ML model and metrics
...

# Step 1: Load the Fashion-MNIST dataset
# the data is already split into training and test sets
(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()

# Step 2: Visualize some samples from the dataset
# It is good practice to visualize some samples from the dataset to get an idea of what the data looks like
# you can visualize the images by using plt.imshow(), where X_train[i] is the image you want to visualize
# you can also use the label y_train[i] to label the image, the label is an integer between 0 and 9
# the labels correspond to the following fashion items:
# 0: T-shirt/top, 1: Trouser, 2: Pullover, 3: Dress, 4: Coat, 5: Sandal, 6: Shirt, 7: Sneaker, 8: Bag, 9: Ankle boot
...

# Step 3: Preprocess the data
# your model must take a 2D array of shape (n_samples, n_features), the data should be normalized to be between 0 and 1
X_train = X_train.reshape(X_train.shape[0], -1) / 255.0  # Normalize and flatten
X_test = X_test.reshape(X_test.shape[0], -1) / 255.0

print(X_train.shape)
print(X_test.shape)

# Step 4: Train your model, this is where you can try different algorithms, make sure the model is assigned to a variable called `model`
...

# Step 5: Evaluate the model
# you can validate your model by checking the accuracy, classification report, and confusion matrix, make sure you are using the test set
...

# Step 6: Display results
# you can display the results by printing the accuracy, classification report, and confusion matrix
...
grader.check("Machine-learning-keras-fashion-mnist")

Submitting Assignment#

Please run the following block of code using shift + enter to submit your assignment, you should see your score.

from pykubegrader.submit.submit_assignment import submit_assignment

submit_assignment("week9-practicequiz", "ML_practice_q")