Question: Hi, I need help for the below question, I have attempt few different code, but all the result shown the answer isn't correct. Please help

Hi, I need help for the below question, I have attempt few different code, but all the result shown the answer isn't correct. Please help me on the code.

Question: Which training examples are the support vectors? Assign the coordinate in the list. e.g. support_vectors = [(1,0),(0,0)]

My code:

import numpy as np from sklearn.svm import SVC #X, y = part2data() X = np.array([[1,8],[7,2],[6,-1],[-5,0], [-5,1], [-5,2],[6,3],[6,1],[5,2]]) y = np.array([1,-1,-1,1,-1,1,1,-1,-1]) def find_support_vectors(X, y, slacks, tol=1e-5): # Get the indices of the non-zero slacks nonzero_slacks = np.where(np.array(slacks) > tol)[0] # Get the indices of the smallest slacks smallest_slacks = np.argwhere(np.array(slacks) <= tol) # Combine the indices support_vector_indices = np.concatenate([nonzero_slacks[:, np.newaxis], smallest_slacks]) # Get the corresponding examples support_vectors = [X[index] for index in support_vector_indices] return support_vectors # Get the support vectors support_vectors = find_support_vectors(X, y, slacks) # Print the support vectors print("Support vectors:", support_vectors) 

My output :

Support vectors: [array([[1, 8]])]

And the result shown an error:

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

I need help for the code. Please help me on this. 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!