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

FIX CalibratedClassifierCV with string targets #28843

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
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
7 changes: 7 additions & 0 deletions 7 doc/whats_new/v1.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ Changelog
:pr:`123456` by :user:`Joe Bloggs <joeongithub>`.
where 123455 is the *pull request* number, not the issue number.

:mod:`sklearn.calibration`
..........................

- |Fix| Fixed a regression in :class:`calibration.CalibratedClassifierCV` where
an error was wrongly raised with string targets.
:pr:`28843` by :user:`Jérémie du Boisberranger <jeremiedbb>`.

:mod:`sklearn.cluster`
......................

Expand Down
4 changes: 1 addition & 3 deletions 4 sklearn/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,7 @@ def fit(self, X, y, sample_weight=None, **fit_params):
n_folds = self.cv.n_splits
else:
n_folds = None
if n_folds and np.any(
[np.sum(y == class_) < n_folds for class_ in self.classes_]
):
if n_folds and np.any(np.unique(y, return_counts=True)[1] < n_folds):
raise ValueError(
f"Requesting {n_folds}-fold "
"cross-validation but provided less than "
Expand Down
11 changes: 11 additions & 0 deletions 11 sklearn/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,3 +1088,14 @@ def predict_proba(self, X):
calibrator = CalibratedClassifierCV(model)
# Does not raise an error
calibrator.fit(*data)


def test_error_less_class_samples_than_folds():
"""Check that CalibratedClassifierCV works with string targets.

non-regression test for issue #28841.
"""
X = np.random.normal(size=(20, 3))
y = ["a"] * 10 + ["b"] * 10

CalibratedClassifierCV(cv=3).fit(X, y)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.