The Wayback Machine - https://web.archive.org/web/20230326205529/https://github.com/scikit-learn/scikit-learn/issues/18955
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

SVC sigmoid kernel is not working properly #18955

Closed
marmor97 opened this issue Dec 2, 2020 · 2 comments
Closed

SVC sigmoid kernel is not working properly #18955

marmor97 opened this issue Dec 2, 2020 · 2 comments
Labels
Bug: triage Reported bugs that are not confirmed

Comments

@marmor97
Copy link

marmor97 commented Dec 2, 2020

Describe the bug

I am testing an SVM with a sigmoid kernel on the iris data. Its performance is extremely poor with an accuracy of 25 %. I'm using exactly the same code and normalizing the features as https://towardsdatascience.com/a-guide-to-svm-parameter-tuning-8bfe6b8a452c (sigmoid section) which should increase performance substantially. However, I am not able to reproduce his results and the accuracy only increases to 33 %.

Using other kernels (e.g linear kernel) produces good results (accuracy of 82 %).
Could there be an issue within the SVC(kernel = 'sigmoid') function?

Steps/Code to Reproduce

##sigmoid iris example
from sklearn import datasets 
iris = datasets.load_iris()
from sklearn.svm import SVC 

sepal_length = iris.data[:,0] 
sepal_width = iris.data[:,1]

#assessing performance of sigmoid SVM
clf = SVC(kernel='sigmoid') 
clf.fit(np.c_[sepal_length, sepal_width], iris.target) 
pr=clf.predict(np.c_[sepal_length, sepal_width])
pd.DataFrame(classification_report(iris.target, pr, output_dict=True))

from sklearn.metrics.pairwise import sigmoid_kernel 
sigmoid_kernel(np.c_[sepal_length, sepal_width]) 

#normalizing features
from sklearn.preprocessing import normalize 
sepal_length_norm = normalize(sepal_length.reshape(1, -1))[0] 
sepal_width_norm = normalize(sepal_width.reshape(1, -1))[0] 
clf.fit(np.c_[sepal_length_norm, sepal_width_norm], iris.target) 
sigmoid_kernel(np.c_[sepal_length_norm, sepal_width_norm]) 

#assessing perfomance of sigmoid SVM with normalized features
pr_norm=clf.predict(np.c_[sepal_length_norm, sepal_width_norm])
pd.DataFrame(classification_report(iris.target, pr_norm, output_dict=True))

Versions

System:
python: 3.8.6 (default, Oct 8 2020, 14:06:32) [Clang 12.0.0 (clang-1200.0.32.2)]
executable: /Users/Marie/Desktop/5 semester/Bachelor/Bachelor_vcode/hello/.venv/bin/python
machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
pip: 20.2.1
setuptools: 49.2.1
sklearn: 0.23.2
numpy: 1.19.2
scipy: 1.5.3
Cython: None
pandas: 1.1.3
matplotlib: 3.3.2
joblib: 0.17.0
threadpoolctl: 2.1.0

Built with OpenMP: True

@marmor97 marmor97 added the Bug: triage Reported bugs that are not confirmed label Dec 2, 2020
@marmor97 marmor97 closed this as completed Dec 2, 2020
@marmor97 marmor97 reopened this Dec 2, 2020
@jeremiedbb
Copy link
Member

jeremiedbb commented Dec 22, 2020

The default value of the gamma parameter changed in version 0.22. The blog post you linked was written before 0.22 so gamma="auto" by default. You're on version 0.23.2 so ```gamma="scale"`` by default. Changing gamma to "auto" retreive the same scores as in the blog post. Besides if you want to tune the gamma parameter, you should do it by cross-validation, not just by looking for the best score on the training set.

@cmarmo
Copy link
Member

cmarmo commented Jan 18, 2021

Hi @marmor97 , it seems to me that your question was answered and you are happy with this answer... :)
I'm closing this issue. Feel free to reopen if you think something still need to be solved.

@cmarmo cmarmo closed this as completed Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: triage Reported bugs that are not confirmed
Projects
None yet
Development

No branches or pull requests

3 participants