Question: def svm _ train ( X , y , num _ iters,batch _ size,reg _ para,learning _ rate ) : # you are going to

def svm_train(X,y,num_iters,batch_size,reg_para,learning_rate):
# you are going to create the training loop and record the training loss each iteration.
W,num_train,num_classes = svm_init(X, y) # init the model
loss_history =[] # this is a list to record all the loss during training
for iteration in range(num_iters): # 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 (3 lines)%%%%%%%%%%%%%%
sample_idxs = # generate the random index from the training dataset wite the same size of batchsize
X_batch = #find all input data X_batch
y_batch = #find all corresponding label y_batch
# %%%%%%%%%%%%%% your code ends here %%%%%%%%%%%%%%
loss, grad = svm_loss(X_batch,y_batch,W,reg_para) # we will implement this loss function in the following section
loss_history.append(loss)
W = svm_weight_update(W,grad,learning_rate) # we will implement this loss function in the following section
if iteration %100==0:
print('iteration %d /%d: loss %f'%(iteration, num_iters, loss))
return loss_history,W

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!