Objective: This lab is designed for you to apply Deep Neural Networks in image classification task. You will try to explore how different choices of hyperparameters such as learning_rate, batch_size, actiavation function, number of epoches, architecture of the network influences the model performance.
The notebook of this TP is available here: TP8_DNN.ipynb.
1. Fashion MNIST Dataset
Fashion-MNIST is a dataset of Zalando’s article images—consisting of a training set of 60, 000 examples and a test set of 10, 000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. Zalando intends Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits, similar to the hand-written digit Minst dataset.
A. Import the dataset into python environment and print the first 12 training items (3 rows and 4 columns) of this dataset with title corresponding to their actual item name (you can find the true label of each item here: https://www.kaggle.com/datasets/zalando-research/fashionmnist).
Check if the classes are balanced or not?
Preprocess the data and target by:
Normalize the input scale.
Perform one-hot encoding on the target.
import kagglehubimport pandas as pdimport numpy as npimport matplotlib.pyplot as plt# To doimport kagglehub# Download latest versionpath = kagglehub.dataset_download("zalando-research/fashionmnist")print("Path to dataset files:", path)data_test = pd.read_csv(path +'/fashion-mnist_test.csv')data_train = pd.read_csv(path +'/fashion-mnist_train.csv')X_train, y_train = data_train.iloc[:,1:], data_train['label']X_test, y_test = data_test.iloc[:,1:], data_test['label']X_train.head()
Path to dataset files: /Users/hassothea/.cache/kagglehub/datasets/zalando-research/fashionmnist/versions/4
B. Build a DNN with your choice of hyperparameters to classify the iterms (You can use your favorite Python modules such as Keras or Pytorch to build the model).
What’s the purpose of the learning curve (train and validation curves)? Plot the learning curve of the training phase.
Compute the confusion matrix of the prediction vs actual label for the test dataset, then compute suitable test metrics of the trained model.
# To do
C. Vary the hyperparameters such as mini-batch, number of epochs, penalty strength,… of the network to improve the performance of the network.
Plot the learning curves of each training phase (when you make change to new hyperparameters, you should retrain the data and plot a new learning curve).
Select a final choice of all hyperparameters and retrain the network. Compute confusion matrix and test metrics.
Plot some misclassified items.
# To do
D. Classical ML Models
Implement and fine-tune some classical ML models we have studied such as:
\(k\)-NN
Random Forest
XGBoost…
to classify the items of the FashionMnist dataset above. - Compute the confusion matrix of each method and evaluate its test metrics then compare to DNN model above. - Conclude.