Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this project, we will be developing a basic neural network from the ground up to classify various types of fashion items. The primary objective
In this project, we will be developing a basic neural network from the ground up to classify various types of fashion items. The primary objective of this project is to gain a comprehensive understanding of neural network architecture, including its theory and implementation details.
Categories in the dataset:
: Tshirttop
: Trouser
: Pullover
: Dress
: Coat
: Sandal
: Shirt
: Sneaker
: Bag
: Ankle boot
# Notice that you don't need any other packages for this midterm
import numpy as np
import pandas as pd
import random
from matplotlib import pyplot as plt
random.seed # NEVER change this line; this is for grading
# Reading the dataset
data pdreadcsvfashiondata.csv
# The data preprocessing is done for you. Please do NOT edit the cell
# However, you should understand what these codes are doing
data nparraydata
m n data.shape
nprandom.shuffledata # shuffle before splitting into dev and training sets
datadev data:T
Ydev datadev
Xdev datadev:n
Xdev Xdev
datatrain data:mT
Ytrain datatrain
Xtrain datatrain:n
Xtrain Xtrain
mtrain Xtrain.shape
# define a global variable specifying the number of hidden neurons after the first layer
# not the best practice, but we will do it for this midterm project
numhiddenneurons
# Initialize the parameters in the neural network
# Based on the figure above, we need the weight and bias matrices.
# W b are the matrices for the first layer
# W b are the matrices for the second layer
# You should think about the sizes of the matrices
# then initialize elements in the matrix to be random numbers between to
def initparams:
W # Your code here
b # Your code here
W # Your code here
b # Your code here
return W b W b
# As a starting point, you only need a ReLu function, its derivative, and the softmax function
def ReLUZ:
# Your code here
def ReLUderivZ:
# Your code here
def softmaxZ:
# Your code here
return A
# In the forward propagation function, X is the inputs the image in vector form and we pass all the weights and biases
def forwardpropW b W b X:
Z # Your code here
A # Your code here
Z # Your code here
A # Your code here
return Z A Z A
# This one hot function is to convert a numeric number into a onehot vector
def onehotY:
# Your code here
return onehotY
# Now performing the backward propagation
# Each function is only one line, but lots of Calculus behind
def backwardpropZ A Z A W W X Y:
onehotY onehotY
dZ # Your code here
dW # Your code here
db # Your code here
dZ # Your code here
dW # Your code here
db # Your code here
return dW db dW db
# Finally, we are ready to update the parameters
def updateparamsW b W b dW db dW db alpha:
W # Your code here
b # Your code here
W # Your code here
b # Your code here
return W b W b
# Implement the helper function. We need to convert the softmax output into a numeric label
# This is done through getpredictions function
def getpredictionsA:
# Your code here
# We also want to have a simple function to compute the accuracy. Notice that "predictions" and Y are the same shape
def getaccuracypredictions Y:
return # Your code here
# Finally, we are ready to implement gradient descent
def gradientdescentX Y alpha, iterations:
W b W b # Your code here using the function you have implemented
for i in rangeiterations:
Z A Z A # Your code here using the function you have implemented
dW db dW db # Your code here using the function you have implemented
W b W b # Your code here using the function you have implemented
if i :
printIteration: i
predictions getpredictionsA
printgetaccuracypredictions Y
return W b W b
#Validate set performance
def makepredictionsX W b W b:
A forwardpropW b W b X
predictions getpredictionsA
return predictions
devpredictions makepredictionsXdev, W b W b
getaccuracydevpredictions, Ydev
Part : Error Analysis and Performance Improvements
You now will try to improve the model performance through, for example, different activation functions, learning rate cahnges, expanding the network complexity, regularization, and dropouts. Implement these ideas for improvement and compare to the base model you completed in part The ideas may not improve the model, they may improve, give reasons why you did or did not succeed in makeing a better model. You must implement at least three different models.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started