Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I need help for this question: Compute the slack i associated with the misclassified points. I had make a few attempt for different code,

Hi, I need help for this question: Compute the slack i associated with the misclassified points.

I had make a few attempt for different code, but after submission the result shown the answer isn't correct. My code as below:

# your code here import numpy as np from sklearn.svm import SVC # your code here clf = SVC(C=1.0, kernel='linear') clf.fit(X, y) #Get the predictions predictions = clf.predict(X) #Get the dual coefficients and bias dual_coef = clf.dual_coef_[0] bias = clf.intercept_[0] #Initialize a list for the slacks slacks = [] for i, example in enumerate(X): if predictions[i] != y[i]: # Compute the slack for misclassified examples slack = 1 - y[i] * (np.dot(example, clf.coef_.T) + bias) slacks.append(slack.item()) print(slacks)

The error for first attempt after submission:

--------------------------------------------------------------------------- NameError Traceback (most recent call last)  in  32 # compute the slack associated with the misclassified points 33 # return a list slacks with the slack computations ---> 34 slacks = [slack1, slack2] 35 slack1 = 1.8333333333333355 36 slack2 = 1.666666666666668
 

Error for second attempt for submission:

--------------------------------------------------------------------------- AssertionError Traceback (most recent call last)  in  Traceback Redacted AssertionError: Check Part 1D. Look at slacks.

Please help me on the code. 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 Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

50. Prove the result in the second proposition, MaXb (t) ebtMX(at).

Answered: 1 week ago