Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a problem in function svm_predict() and the prediction cannot be implemented correctly #4

Open
Cuisine4 opened this issue Mar 31, 2023 · 1 comment

Comments

@Cuisine4
Copy link

Describe the bug
The problem appears on line 238 of file svm.py.In the original program, the formula for calculating the self.bias is as follows.
# Compute the bias
k = self.kernel(X_train, X_test)
SV_neg = y_train < 0
SV_pos = y_train > 0
self.bias = (-1 / 2) * (np.max(k[SV_neg[:, 0], :].T @ alpha[SV_neg]) + np.min(k[SV_pos[:, 0], :].T @ alpha[SV_pos]))
self.bias = y_train - np.sum(alpha * y_train * k, axis=1, keepdims=True)
self.bias = np.mean(self.bias)
The bias calculated in this way is incorrect and will cause errors in later predictions

Expected behavior
According to the formula I looked up, the correct calculation is as follows.
# Compute the bias
k = self.kernel(X_train, X_test)
SV_neg = y_train < 0
SV_pos = y_train > 0
kk=self.kernel(X_train, X_train)
self.bias = y_train - np.sum(alpha * y_train * kk, axis=1, keepdims=True)
self.bias = np.mean(self.bias)

Screenshots
Screenshot from the watermelon book "Machine learning" Zhou Zhihua section 6.2
image

@github-actions
Copy link

Thanks for submitting an issue.' first issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant