Question: Hi, I need help for this question: Which training examples have nonzero slack? List their coordinates. I have make few attempt on the code but

Hi, I need help for this question: Which training examples have nonzero slack? List their coordinates. I have make few attempt on the code but still get wrong and the result shown an error. Please help me on the code. My code:

import numpy as np from sklearn.svm import SVC # Load the data using part2data() X, y = part2data() # Train the SVM model with a linear kernel clf = SVC(kernel='linear') clf.fit(X, y) # Obtain the decision function values for each training example decision_function = clf.decision_function(X) # Compute the slack variables for each training example slack = 1 - y * decision_function # Find the training examples with nonzero slack nonzero_slack_indices = np.where(slack > 0)[0] print("Training examples with nonzero slack:", nonzero_slack_indices)

My answer:

Training examples with nonzero slack: [ 4 5 11 12 16 20 21]

The error:

--------------------------------------------------------------------------- AssertionError Traceback (most recent call last)  in  Traceback Redacted AssertionError: Look at Part 1C. Look at nonzero_slack.

Please help me on the code. Thank you so much.

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 Databases Questions!