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

Unexpected prediction from SVM #312

Open
aymanosman opened this issue Nov 30, 2024 · 3 comments
Open

Unexpected prediction from SVM #312

aymanosman opened this issue Nov 30, 2024 · 3 comments

Comments

@aymanosman
Copy link

I get unexpected predictions from the SVM module.

This example is taken from the docs:

x = Nx.tensor([[1.0, 2.0], [3.0, 2.0], [4.0, 7.0]])
y = Nx.tensor([1, 0, 1])
model = Scholar.Linear.SVM.fit(x, y, num_classes: 2)
Scholar.Linear.SVM.predict(model, x)
#Nx.Tensor<
  s32[3]
  [1, 1, 1]
>

I expected to see [1, 0, 1].

Here is a livebook demonstrating the behaviour https://gist.github.com/aymanosman/aa20b3832148260d257cf43e2d497cc4.

@josevalim
Copy link
Contributor

Why do you believe this behaviour is expected? Looking at Python, I get the same behaviour:

>>> x = [[1.0, 2.0], [3.0, 2.0], [4.0, 7.0]]
>>> y = [1, 0, 1]
>>> clf = svm.SVC()
>>> clf.fit(x, y)
SVC()
>>> clf.predict(x)
array([1, 1, 1])

I think the small sample size and the unbalanced classes are not being helpful to draw the correct planes.

@aymanosman
Copy link
Author

Why do you believe this behaviour is expected? Looking at Python, I get the same behaviour:

Because I am a n00b.

@aymanosman
Copy link
Author

Although...

from sklearn.linear_model import SGDClassifier
x = [[1.0, 2.0], [3.0, 2.0], [4.0, 7.0]]
y = [1, 0, 1]
clf = SGDClassifier()
clf.fit(x, y)
print(clf.predict(x))
# => [1 0 1]

@aymanosman aymanosman reopened this Nov 30, 2024
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

2 participants