Question: Hyperparameter Selection on MNIST The goal of this assignment is to design, train, and optimize a neural network using PyTorch with only linear layers and
Hyperparameter Selection on MNIST
The goal of this assignment is to design, train, and optimize a neural network using PyTorch with only linear layers and nonlinear activations to achieve at least accuracy on the MNIST dataset. You will perform basic hyperparameter tuning to meet this target.
Data preparation
Utilize torchvision.datasets.MNIST to load the training and test datasets. You will need a validation set to optimize your parameters. Use of the training data as your validation set.
Use torch, torch.nn torch.optim, torchvision, and other required modules.
Load the MNIST dataset.
Utilize torchvision.datasets.MNIST to load the training and test datasets.
Normalize the images to a range of using torchvision.transforms.
Use the DataLoader class for batch processing.
Neural network
Design a neural network architecture using only linear layers. Ensure the model contains the following,
An input layer compatible with the MNIST image size.
One or more hidden layers.
An output layer compatible for multiclass classification task and the MNIST dataset.
Use appropriate activation and loss functions and explain why they were chosen. Training & Evaluation
Choose your optimizer, learning rate scheduler and implement a training loop to train your model. Keep track of your training and validation losses, you will be asked to plot and discuss them later on In this stage, you will not be touching the test set in any way. You may only work on training and validation sets. Try to get an accuracy score of at least on the validation set. Experiment with different hyperparameters, including:
Learning rate.
Number of hidden layers and neurons in each layer.
Batch size.
Number of epochs.
Record the hyperparameters and their effects on the model's performance. Calculate the training and validation accuracy for each hyperparameter combination and plot the losses. Report the accuracies in a printed DataFrame for each hyperparameter. Comment on your results and explain the table. Finally, select the best model and calculate the accuracy on the test set. Do not perform any hyperparameter tuning after calculating the test set accuracy.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
