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

Wrong results for single-prediction sparse-matrix input to SVC #1880

Open
Simon2496 opened this issue Jun 19, 2024 · 2 comments
Open

Wrong results for single-prediction sparse-matrix input to SVC #1880

Simon2496 opened this issue Jun 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Simon2496
Copy link

Simon2496 commented Jun 19, 2024

Describe the bug
The bug occurs if a single sample in sparse-matrix format is given to a SVM classifier. The prediction made by the SVM classifier differs from batch prediction, which gives the correct prediction. Furthermore, the problem occurs for both predict and predict_proba.

To Reproduce
The following code gives a minimal example:

from sklearnex import patch_sklearn
patch_sklearn()

import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import SVC

X = np.array(['hello world there', 'hello planet earth'])
y = np.array([1, 0])

test_1 = ['earth']
test_2 = ['earth', 'earth']

svm = SVC(probability=True)
vectorizer = TfidfVectorizer()

svm.fit(vectorizer.fit_transform(X), y)

print(svm.predict_proba(vectorizer.transform(test_1)))
print(svm.predict_proba(vectorizer.transform(test_2)))

Expected behavior
The output gives different results for the probabilities of a sample predicted alone versus predicted as batch. This is not correct, instead, the probabilities should be the same. The problem vanishes if sklearnex is disabled.

Output/Screenshots
This is the output of the minimal example:

[[0.5 0.5]]
[[0.52834581 0.47165419]
 [0.52834581 0.47165419]]
@Simon2496 Simon2496 added the bug Something isn't working label Jun 19, 2024
@Simon2496 Simon2496 changed the title Wrong predictions for single-processing sparse-matrix input to SVC Wrong predictions for single-prediction sparse-matrix input to SVC Jun 19, 2024
@Simon2496 Simon2496 changed the title Wrong predictions for single-prediction sparse-matrix input to SVC Wrong results for single-prediction sparse-matrix input to SVC Jun 19, 2024
@samir-nasibli
Copy link
Contributor

Thank you @Simon2496 for the report!
In order to reproduce the issues, please share the version of daal4py and scikit-learn-intelex and more details about your env.

@Simon2496
Copy link
Author

Simon2496 commented Jun 21, 2024

I have the most recent versions installed. Concretely, I have the following versions:

  • daal4py==2024.4.0
  • numpy==1.23.5
  • scikit-learn==1.5.0
  • scikit-learn-intelex==2024.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants