Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

9. Explain the relationship between identity and communication.

Answered: 1 week ago

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago