Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
I am using these Libraries. import numpy as np from pylab import * from numpy.matlib import repmat import matplotlib.pyplot as plt from scipy.io import loadmat
I am using these Libraries. import numpy as np from pylab import from numpy.matlib import repmat import matplotlib.pyplot as plt from scipy.io import loadmat import time matplotlib notebook from helper import Can yodef gridsearchxTr yTr xVal, yVal, depths: Calculates the training and validation loss for trees trained on xTr and validated on yTr with a number of depths. Input: xTr: nxd training data matrix yTr: ndimensional vector of training labels xVal: mxd validation data matrix yVal: mdimensional vector of validation labels depths: a list of len k of depths Output: bestdepth, traininglosses, validationlosses bestdepth: the depth that yields that lowest validation loss traininglosses: a list of len k the ith entry corresponds to the the training loss of the tree of depthdepthsi validationlosses: a list of len k the ith entry corresponds to the the validation loss of the tree of depthdepthsi traininglosses validationlosses bestdepth None # Initialize the variable bestloss floatinf # Loop over all possible depths for the regression tree for dept in depths: # Check if the current validation is less than the best validation loss if validationloss bestloss: bestloss validationloss bestdepth depth raise NotImplementedError return bestdepth, traininglosses, validationlossesu help fix the code using the above libraries?
I am using these Libraries.
import numpy as np
from pylab import
from numpy.matlib import repmat
import matplotlib.pyplot as plt
from scipy.io import loadmat
import time
matplotlib notebook
from helper import
Can yodef gridsearchxTr yTr xVal, yVal, depths:
Calculates the training and validation loss for trees trained on xTr and validated on yTr with a number of depths.
Input:
xTr: nxd training data matrix
yTr: ndimensional vector of training labels
xVal: mxd validation data matrix
yVal: mdimensional vector of validation labels
depths: a list of len k of depths
Output:
bestdepth, traininglosses, validationlosses
bestdepth: the depth that yields that lowest validation loss
traininglosses: a list of len k the ith entry corresponds to the the training loss of the tree of depthdepthsi
validationlosses: a list of len k the ith entry corresponds to the the validation loss of the tree of depthdepthsi
traininglosses
validationlosses
bestdepth None
# Initialize the variable
bestloss floatinf
# Loop over all possible depths for the regression tree
for dept in depths:
# Check if the current validation is less than the best validation loss
if validationloss bestloss:
bestloss validationloss
bestdepth depth
raise NotImplementedError
return bestdepth, traininglosses, validationlossesu help fix the code using the above libraries?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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