Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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