Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored 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