8000 FIX deprecate calibrators_ in _CalibratedClassifier (#18714) · scikit-learn/scikit-learn@9358a94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9358a94

Browse files
authored
FIX deprecate calibrators_ in _CalibratedClassifier (#18714)
1 parent 60945b4 commit 9358a94

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

examples/calibration/plot_calibration_multiclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class of an instance (red: class 1, green: class 2, blue: class 3).
141141
calibrated_classifier = sig_clf.calibrated_classifiers_[0]
142142
prediction = np.vstack([calibrator.predict(this_p)
143143
for calibrator, this_p in
144-
zip(calibrated_classifier.calibrators_, p.T)]).T
144+
zip(calibrated_classifier.calibrators, p.T)]).T
145145
prediction /= prediction.sum(axis=1)[:, None]
146146

147147
# Plot modifications of calibrator

sklearn/calibration.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
from .base import (BaseEstimator, ClassifierMixin, RegressorMixin, clone,
2424
MetaEstimatorMixin)
2525
from .preprocessing import label_binarize, LabelEncoder
26-
from .utils import check_array, indexable, column_or_1d
26+
from .utils import (
27+
check_array,
28+
column_or_1d,
29+
deprecated,
30+
indexable,
31+
)
2732
from .utils.multiclass import check_classification_targets
2833
from .utils.fixes import delayed
2934
from .utils.validation import check_is_fitted, check_consistent_length
@@ -585,6 +590,16 @@ class _CalibratedClassifier:
585590
The method to use for calibration. Can be 'sigmoid' which
586591
corresponds to Platt's method or 'isotonic' which is a
587592
non-parametric approach based on isotonic regression.
593+
594+
Attributes
595+
----------
596+
calibrators_ : list of fitted estimator instances
597+
Same as `calibrators`. Exposed for backward-compatibility. Use
598+
`calibrators` instead.
599+
600+
.. deprecated:: 0.24
601+
`calibrators_` is deprecated from 0.24 and will be removed in
602+
0.26. Use `calibrators` instead.
588603
"""
589604
def __init__(self, base_estimator, calibrators, *, classes,
590605
method='sigmoid'):
@@ -593,6 +608,16 @@ def __init__(self, base_estimator, calibrators, *, classes,
593608
self.classes = classes
594609
self.method = method
595610

611+
# TODO: Remove in 0.26
612+
# mypy error: Decorated property not supported
613+
@deprecated( # type: ignore
614+
"calibrators_ is deprecated in 0.24 and will be removed in 0.26. "
615+
"Use calibrators instead."
616+
)
617+
@property
618+
def calibrators_(self):
619+
return self.calibrators
620+
596621
def predict_proba(self, X):
597622
"""Calculate calibrated probabilities.
598623

sklearn/tests/test_calibration.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,19 @@ def test_calibration_attributes(clf, cv):
542542
classes = LabelEncoder().fit(y).classes_
543543
assert_array_equal(calib_clf.classes_, classes)
544544
assert calib_clf.n_features_in_ == X.shape[1]
545+
546+
547+
# FIXME: remove in 0.26
548+
def test_calibrated_classifier_cv_deprecation(data):
549+
# Check that we raise the proper deprecation warning if accessing
550+
# `calibrators_` from the `_CalibratedClassifier`.
551+
X, y = data
552+
calib_clf = CalibratedClassifierCV(cv=2).fit(X, y)
553+
554+
with pytest.warns(FutureWarning):
555+
calibrators = calib_clf.calibrated_classifiers_[0].calibrators_
556+
557+
for clf1, clf2 in zip(
558+
calibrators, calib_clf.calibrated_classifiers_[0].calibrators
559+
):
560+
assert clf1 is clf2

0 commit comments

Comments
 (0)
0