Skip to content

sklearn/tuned-threshold-prefit-refit

Pack Severity Fix Versions
scikit-learn error none, edit by hand All versions

TunedThresholdClassifierCV(..., cv="prefit") raises ValueError: When cv='prefit', refit cannot be True. because refit defaults to True.

tuned = TunedThresholdClassifierCV(clf, cv="prefit", scoring="f1")
tuned = TunedThresholdClassifierCV(clf, cv="prefit", refit=False, scoring="f1")

Calls to sklearn.model_selection.TunedThresholdClassifierCV with cv="prefit" that omit refit=False.

Pass refit=False and fit on a held-out calibration split (never on training rows), or pass a real cross-validation splitter to cv= so threshold tuning runs out of fold.

TunedThresholdClassifierCV with cv="prefit" defaults to refit=True and raises ValueError("When cv='prefit', refit cannot be True.") on fit. Pass refit=False and fit on held-out calibration rows, or use cross-validation splits instead of "prefit".

See all rules in the scikit-learn pack.