You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LogisticRegressionCV with scoring = "neg_brier_score" fails when a CV test split is missing a class. #33207
neg_brier_score uses brier_score_loss, which requires labels when y_true does not include all classes. In LogisticRegressionCV, the scorer is called without labels, even though the estimator is trained on all classes and probabilities are emitted for all classes. This causes a ValueError if any test fold misses a class. There is already a FIXMEin the source noting exactly this. The scoring should pass labels=classes (or equivalent) to be robust.
Minimal Reproduction
importnumpyasnpfromsklearn.datasetsimportmake_classificationfromsklearn.linear_modelimportLogisticRegressionCVimportsklearnprint("sklearn", sklearn.__version__)
X, y=make_classification(
n_samples=90,
n_features=8,
n_informative=6,
n_redundant=0,
n_classes=3,
n_clusters_per_class=1,
random_state=0,
)
idx0=np.flatnonzero(y==0)
idx1=np.flatnonzero(y==1)
idx2=np.flatnonzero(y==2)
# Fold 0 test set has only classes 0 and 1test0=np.concatenate([idx0[:10], idx1[:10]])
train0=np.setdiff1d(np.arange(len(y)), test0)
# Fold 1 test set has only class 2test1=idx2[:10]
train1=np.setdiff1d(np.arange(len(y)), test1)
cv= [(train0, test0), (train1, test1)]
clf=LogisticRegressionCV(
cv=cv,
scoring="neg_brier_score",
solver="lbfgs",
max_iter=200,
)
clf.fit(X, y)
I've reproduced the issue and identified the root cause. The problem occurs in _log_reg_scoring_path() when using neg_brier_score or similar metrics that rely on brier_score_loss. When a CV test split is missing a class, the scorer needs explicit labels parameter to know about all classes that the model was trained on.
Proposed fix: In _log_reg_scoring_path(), when the scoring method is "neg_brier_score" or "brier_score_loss", we should pass labels=classes to the scorer call. This ensures the Brier score calculation considers all classes, even if they're not present in the test fold.
The fix is minimal and addresses the exact scenario described in the FIXME comment and issue #33207 that's already in the code. This will make LogisticRegressionCV robust to class imbalance in cross-validation folds when using Brier score-based metrics.
I've reproduced the issue and identified the root cause. The problem occurs in _log_reg_scoring_path() when using neg_brier_score or similar metrics that rely on brier_score_loss. When a CV test split is missing a class, the scorer needs explicit labels parameter to know about all classes that the model was trained on.
Proposed fix: In _log_reg_scoring_path(), when the scoring method is "neg_brier_score" or "brier_score_loss", we should pass labels=classes to the scorer call. This ensures the Brier score calculation considers all classes, even if they're not present in the test fold.
The fix is minimal and addresses the exact scenario described in the FIXME comment and issue #33207 that's already in the code. This will make LogisticRegressionCV robust to class imbalance in cross-validation folds when using Brier score-based metrics.
the implementation checks whether the scorer supports a labels parmeter before passing it. This fixes neg_brier_score as noted in FIXME, and also covers closely related probabilistic scorers (like neg_log_loss) that rely on full class information when some classes are absent from a CV fold.
For built-in sklearn scorers, labels is added to a shallow copy of the scorer’s parameters to avoid mutating user-provided objects and to respect existing metadata routing behavior. No user-facing configuration is required
Activity
rohandhar6824-debug commentedon Feb 5, 2026
I've reproduced the issue and identified the root cause. The problem occurs in _log_reg_scoring_path() when using neg_brier_score or similar metrics that rely on brier_score_loss. When a CV test split is missing a class, the scorer needs explicit labels parameter to know about all classes that the model was trained on.
Proposed fix: In _log_reg_scoring_path(), when the scoring method is "neg_brier_score" or "brier_score_loss", we should pass labels=classes to the scorer call. This ensures the Brier score calculation considers all classes, even if they're not present in the test fold.
The fix is minimal and addresses the exact scenario described in the FIXME comment and issue #33207 that's already in the code. This will make LogisticRegressionCV robust to class imbalance in cross-validation folds when using Brier score-based metrics.
un1u3 commentedon Feb 5, 2026
the implementation checks whether the scorer supports a labels parmeter before passing it. This fixes
neg_brier_scoreas noted inFIXME, and also covers closely related probabilistic scorers (likeneg_log_loss) that rely on full class information when some classes are absent from a CV fold.For built-in sklearn
scorers,labelsis added to a shallow copy of the scorer’s parameters to avoid mutating user-provided objects and to respect existing metadata routing behavior. No user-facing configuration is requiredrohandhar6824-debug commentedon Feb 5, 2026
Thank you.
Implemented your exact approach
adrinjalali commentedon Feb 5, 2026
Duplicate of #15389