Question: Now that we have defined our needed functions, we can train and test the model, and then plot / report the results below. We first
Now that we have defined our needed functions, we can train and test the model, and then plot report the results below.
We first train the model with no regularization.
nprandom.seed # DO NOT MODIFY THE SEED
m n Xtrain.shape
# Initialize parameters
# Training with no regularization
printComputing for sensory score with no regularization"
start time.time
w initializeparametersn
Xtrain npconcatenateXtrain, nponesXtrain.shape
wnoreg, lossnoreg trainXtrain, ytrain, w regularizationtypeNOREGULARIZATION
noregtrainduration time.time start
# Testing with no regularization
Xtest npconcatenateXtest, nponesXtest.shape
testlossnoreg testXtest, ytest, w NOREGULARIZATION
printGRADIENT DESCENT
plotlosslossnoreg, title"Loss for Sensory Score Prediction with no regularization"
pltsavefigsensoryscorenoreg.png
printFinal training loss achieved lossformatlosslossnoreg
printTest loss achieved lossformatlosstestlossnoreg
printDuration timeformattimenoregtrainduration
We now train the model with l regularization.
# Training with l regularization
printComputing for sensory score with l regularization"
start time.time
w initializeparametersn
Xtrain npconcatenateXtrain, nponesXtrain.shape
wlreg, losslreg trainXtrain, ytrain, w regularizationtypeLLOSS
lregtrainduration time.time start
# Testing with l regularization
Xtest npconcatenateXtest, nponesXtest.shape
testlosslreg testXtest, ytest, w LLOSS
printGRADIENT DESCENT
plotlosslosslreg, title"Loss for Sensory Score Prediction with l regularization"
pltsavefigsensoryscorelreg.png
printFinal training loss achieved lossformatlosslosslreg
printTest loss achieved lossformatlosstestlosslreg
printDuration timeformattimelregtrainduration
We now train the model with l regularization
# Training with l regularization
printComputing for sensory score with l regularization"
start time.time
w initializeparametersn
Xtrain npconcatenateXtrain, nponesXtrain.shape
wlreg, losslreg trainXtrain, ytrain, w regularizationtypeLLOSS
lregtrainduration time.time start
# Testing with l regularization
Xtest npconcatenateXtest, nponesXtest.shape
testlosslreg testXtest, ytest, w LLOSS
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
