Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Issue #19614: Warn on irrelevant parameters for linear kernel in SVC #28641

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

Issac-Kondreddy
Copy link

Fixes #XXXX

This pull request addresses the issue raised in #19614, where SVC does not warn users when irrelevant parameters (gamma, coef0, degree) are set for the linear kernel. Such parameters have no effect and can mislead users, especially those new to SVM or scikit-learn.

Changes Made:

  • Modified svm/_classes.py to issue warnings when gamma, coef0, or degree is set to non-default values while using a linear kernel.

Rationale:

The changes improve user feedback and contribute to a more intuitive user experience by notifying users of potentially unintended parameter configurations. This approach follows scikit-learn's principles of transparency and user-friendliness in machine learning model configuration.

Copy link

❌ Linting issues

This PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling pre-commit hooks. Instructions to enable them can be found here.

You can see the details of the linting issues under the lint job here


black

black detected issues. Please run black . locally and push the changes. Here you can see the detected issues. Note that running black might also fix some of the issues which might be detected by ruff. Note that the installed black version is black=23.3.0.


--- /home/runner/work/scikit-learn/scikit-learn/sklearn/svm/_classes.py	2024-03-17 02:01:18.825534 +0000
+++ /home/runner/work/scikit-learn/scikit-learn/sklearn/svm/_classes.py	2024-03-17 02:01:41.980470 +0000
@@ -319,23 +319,35 @@
         )
 
         check_classification_targets(y)
 
         self.classes_ = np.unique(y)
-        if self.kernel == 'linear':
-            if self.gamma not in ('scale', 'auto'):
+        if self.kernel == "linear":
+            if self.gamma not in ("scale", "auto"):
                 warn(
-                    "The 'gamma' parameter has been set but is not relevant for the 'linear' kernel. It will be ignored.",
-                    UserWarning)
+                    (
+                        "The 'gamma' parameter has been set but is not relevant for the"
+                        " 'linear' kernel. It will be ignored."
+                    ),
+                    UserWarning,
+                )
             if self.coef0 != 0:
                 warn(
-                    "The 'coef0' parameter has been set but is not relevant for the 'linear' kernel. It will be ignored.",
-                    UserWarning)
+                    (
+                        "The 'coef0' parameter has been set but is not relevant for the"
+                        " 'linear' kernel. It will be ignored."
+                    ),
+                    UserWarning,
+                )
             if self.degree != 3:
                 warn(
-                    "The 'degree' parameter has been set but is not relevant for the 'linear' kernel. It will be ignored.",
-                    UserWarning)
+                    (
+                        "The 'degree' parameter has been set but is not relevant for"
+                        " the 'linear' kernel. It will be ignored."
+                    ),
+                    UserWarning,
+                )
 
         _dual = _validate_dual_parameter(
             self.dual, self.loss, self.penalty, self.multi_class, X
         )
 
would reformat /home/runner/work/scikit-learn/scikit-learn/sklearn/svm/_classes.py

Oh no! 💥 💔 💥
1 file would be reformatted, 915 files would be left unchanged.

ruff

ruff detected issues. Please run ruff --fix --show-source . locally, fix the remaining issues, and push the changes. Here you can see the detected issues. Note that the installed ruff version is ruff=0.3.3.


warning: The `--show-source` argument is deprecated. Use `--output-format=full` instead.
sklearn/svm/_classes.py:1:1: I001 [*] Import block is un-sorted or un-formatted
   |
 1 | / import warnings
 2 | | from warnings import warn
 3 | | from numbers import Integral, Real
 4 | | 
 5 | | import numpy as np
 6 | | 
 7 | | from ..base import BaseEstimator, OutlierMixin, RegressorMixin, _fit_context
 8 | | from ..linear_model._base import LinearClassifierMixin, LinearModel, SparseCoefMixin
 9 | | from ..utils._param_validation import Hidden, Interval, StrOptions
10 | | from ..utils.multiclass import check_classification_targets
11 | | from ..utils.validation import _num_samples
12 | | from ._base import BaseLibSVM, BaseSVC, _fit_liblinear, _get_liblinear_solver_type
13 | | 
14 | | 
15 | | def _validate_dual_parameter(dual, loss, penalty, multi_class, X):
   | |_^ I001
16 |       """Helper function to assign the value of dual parameter."""
17 |       if dual == "auto":
   |
   = help: Organize imports

sklearn/svm/_classes.py:327:89: E501 Line too long (122 > 88)
    |
325 |             if self.gamma not in ('scale', 'auto'):
326 |                 warn(
327 |                     "The 'gamma' parameter has been set but is not relevant for the 'linear' kernel. It will be ignored.",
    |                                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501
328 |                     UserWarning)
329 |             if self.coef0 != 0:
    |

sklearn/svm/_classes.py:331:89: E501 Line too long (122 > 88)
    |
329 |             if self.coef0 != 0:
330 |                 warn(
331 |                     "The 'coef0' parameter has been set but is not relevant for the 'linear' kernel. It will be ignored.",
    |                                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501
332 |                     UserWarning)
333 |             if self.degree != 3:
    |

sklearn/svm/_classes.py:335:89: E501 Line too long (123 > 88)
    |
333 |             if self.degree != 3:
334 |                 warn(
335 |                     "The 'degree' parameter has been set but is not relevant for the 'linear' kernel. It will be ignored.",
    |                                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501
336 |                     UserWarning)
    |

Found 4 errors.
[*] 1 fixable with the `--fix` option.

Generated for commit: 4a78b6a. Link to the linter CI: here

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Issac-Kondreddy. There are linting issues that you can fix following the instructions in #28641 (comment).

self.classes_ = np.unique(y)
if self.kernel == 'linear':
if self.gamma not in ('scale', 'auto'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's warn for all non-default values

Suggested change
if self.gamma not in ('scale', 'auto'):
if self.gamma != "scale":

@miguelcsilva
Copy link
Contributor

@Issac-Kondreddy let me know if you're still working on this. Otherwise would be happy to take this on.

@StefanieSenger
Copy link
Contributor

This PR will also close #19630; in fact it's a bit of a duplicate to it.

@lamdang2k
Copy link
Contributor

I assume that this PR is stalled and proposed a new PR to fix linting issues

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

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.