Question: def svm _ train ( X , y , num _ iters,batch _ size,reg _ para,learning _ rate ) : # you are going to
def svmtrainXynumiters,batchsize,regpara,learningrate:
# you are going to create the training loop and record the training loss each iteration.
Wnumtrain,numclasses svminitX y # init the model
losshistory # this is a list to record all the loss during training
for iteration in rangenumiters: # create this "for" loop to train the model.
# randomly sample the indexs of training data and find the corresponding data and label
# implement your code below lines
sampleidxs # generate the random index from the training dataset wite the same size of batchsize
Xbatch #find all input data Xbatch
ybatch #find all corresponding label ybatch
# your code ends here
loss, grad svmlossXbatch,ybatch,Wregpara # we will implement this loss function in the following section
losshistory.appendloss
W svmweightupdateWgrad,learningrate # we will implement this loss function in the following section
if iteration :
printiteration d d: loss fiteration numiters, loss
return losshistory,W
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
