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")What the rule reports
Section titled “What the rule reports”Calls to sklearn.model_selection.TunedThresholdClassifierCV with cv="prefit" that omit refit=False.
How to fix it
Section titled “How to fix it”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.
Diagnostic message
Section titled “Diagnostic message”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.