question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Give feedback when `svm.SVC` is configured with kernel hyperparameters for a different kernel

See original GitHub issue

During our class we noticed some students incorrectly configure some hyperparameters which are irrelevant to the kernel used, for example setting gamma when using a linear kernel. We think it could make sense for scikit-learn to give feedback to the user when non-effective settings are configured.

Describe the workflow you want to enable

from sklearn.datasets import load_iris
from sklearn.svm import SVC

x, y = load_iris(return_X_y=True)
clf = SVC(kernel='linear', gamma=1e-6)
clf.fit(x, y)
print(clf.score(x, y))

current output:

0.9933333333333333

proposed output, something similar to:

UserWarning: Gamma is set but not used because a linear kernel is configured.
0.9933333333333333

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
PGijsberscommented, Mar 7, 2021

I’ll update the PR when there is a new consensus (the PR has a FutureWarning instead of DeprecationWarning right now) 😃 just let me know

1reaction
NicolasHugcommented, Mar 5, 2021

the validation should happen in fit (more details here if you’re interested https://scikit-learn.org/stable/developers/develop.html#instantiation)

Also please make sure to write a non-regression test for the cases that are worth testing. The test should make sure that the error is now properly raised. Your snippet above is a great candidate.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

KNN-SVM-SVM with Kernel-Hyperparameter - Kaggle
SVC Implementation is based on libsvm(library for Support Vector Machines). C is the Regularization parameter in SVC and its float with default value...
Read more >
SVM and Kernel SVM - Towards Data Science
In this article, you will learn about SVM or Support Vector Machine, which is one of the most ... classifier = SVC(kernel =...
Read more >
sklearn.svm.SVC — scikit-learn 1.2.0 documentation
Specifies the kernel type to be used in the algorithm. If none is given, 'rbf' will be used. If a callable is given...
Read more >
Simple Tutorial on SVM and Parameter Tuning in Python and R
It follows a technique called the kernel trick to transform the data ... We can see that it is possible to separate the...
Read more >
Support Vector Machine (SVM) Hyperparameter Tuning In ...
The default kernel function for the python implementation of the support vector classifier is the Radial Basis Function, which is usually referred to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found