Skip to content

MAINT Parameters validation for svm.l1_min_c #24865

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

Merged
merged 8 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions sklearn/svm/_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
# Author: Paolo Losi
# License: BSD 3 clause

from numbers import Real

import numpy as np

from ..preprocessing import LabelBinarizer
from ..utils.validation import check_consistent_length, check_array
from ..utils.extmath import safe_sparse_dot
from ..utils._param_validation import StrOptions, Interval, validate_params


@validate_params(
{
"X": ["array-like", "sparse matrix"],
"y": ["array-like"],
"loss": [StrOptions({"squared_hinge", "log"})],
"fit_intercept": ["boolean"],
"intercept_scaling": [Interval(Real, 0, None, closed="neither")],
}
)
def l1_min_c(X, y, *, loss="squared_hinge", fit_intercept=True, intercept_scaling=1.0):
"""Return the lowest bound for C.

Expand Down Expand Up @@ -49,8 +61,6 @@ def l1_min_c(X, y, *, loss="squared_hinge", fit_intercept=True, intercept_scalin
l1_min_c : float
Minimum value for C.
"""
if loss not in ("squared_hinge", "log"):
raise ValueError('loss type not in ("squared_hinge", "log")')

X = check_array(X, accept_sparse="csc")
check_consistent_length(X, y)
Expand Down
12 changes: 0 additions & 12 deletions sklearn/svm/tests/test_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ def test_l1_min_c(loss, X_label, Y_label, intercept_label):
check_l1_min_c(X, Y, loss, **intercept_params)


def test_l1_min_c_l2_loss():
# loss='l2' should raise ValueError
msg = "loss type not in"
with pytest.raises(ValueError, match=msg):
l1_min_c(dense_X, Y1, loss="l2")


def check_l1_min_c(X, y, loss, fit_intercept=True, intercept_scaling=1.0):
min_c = l1_min_c(
X,
Expand Down Expand Up @@ -76,11 +69,6 @@ def test_ill_posed_min_c():
l1_min_c(X, y)


def test_unsupported_loss():
with pytest.raises(ValueError):
l1_min_c(dense_X, Y1, loss="l1")


_MAX_UNSIGNED_INT = 4294967295


Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

PARAM_VALIDATION_FUNCTION_LIST = [
"sklearn.cluster.kmeans_plusplus",
"sklearn.svm.l1_min_c",
]


Expand Down