Repository navigation
Description
Warning
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
Introduce yourself
I am Hamza Abdelhedi, a PhD student at Mila. I build NeuroAI decoding pipelines on scikit-learn, and I opened #35421 for the same gap in scorers.
Describe the bug and give evidence about its user-facing impact
With metadata routing on, CalibratedClassifierCV routes metadata from fit only to the estimator's fit and to the splitter (get_metadata_routing maps fit -> fit). The predictions it calibrates on, made on each held-out fold in _fit_classifier_calibrator_pair, call _get_response_values(estimator, X_test, ...) with no metadata, and its own predict_proba/predict take none.
A pipeline step that needs metadata at transform time therefore breaks under calibration. In EEG decoding, a scaler that centers each subject on its own mean needs groups in transform; the plain pipeline routes it, but calibrating that pipeline raises, or, if groups is optional in the step, silently calibrates on uncentered data.
Related: #27977 is the same gap for scorers, fixed by #35421 (built on #31654); #35523 is about calibration and the splitter's groups with ensemble=False.
Steps/Code to Reproduce
import numpy as np
from sklearn import set_config
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.calibration import CalibratedClassifierCV
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
set_config(enable_metadata_routing=True)
class GroupCentering(TransformerMixin, BaseEstimator):
"""Centers each group on its own mean: transform needs the groups."""
def fit(self, X, y=None, groups=None):
return self
def fit_transform(self, X, y=None, groups=None):
return self.fit(X, y, groups=groups).transform(X, groups=groups)
def transform(self, X, groups=None):
if groups is None:
raise ValueError("transform got no groups")
X = np.array(X, dtype=float)
for g in np.unique(groups):
X[groups == g] -= X[groups == g].mean(axis=0)
return X
rng = np.random.default_rng(0)
X = rng.normal(size=(60, 3))
y = np.tile([0, 1], 30)
groups = np.repeat(np.arange(12), 5)
pipe = make_pipeline(
GroupCentering().set_fit_request(groups=True).set_transform_request(groups=True),
LogisticRegression(),
)
# the pipeline routes groups to transform in fit and in predict_proba
pipe.fit(X, y, groups=groups).predict_proba(X, groups=groups)
# the held-out predictions it calibrates on get no groups
CalibratedClassifierCV(pipe, cv=3).fit(X, y, groups=groups)Expected Results
No error: each held-out fold's predictions get that fold's groups, as the plain pipeline's predict_proba(X, groups=groups) does, and CalibratedClassifierCV.predict_proba(X, groups=groups) routes them to the estimator.
Actual Results
Traceback (most recent call last):
File "repro.py", line 42, in <module>
CalibratedClassifierCV(pipe, cv=3).fit(X, y, groups=groups)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/sklearn/base.py", line 1403, in wrapper
return fit_method(estimator, *args, **kwargs)
File ".../site-packages/sklearn/calibration.py", line 441, in fit
self.calibrated_classifiers_ = parallel(
~~~~~~~~^
delayed(_fit_classifier_calibrator_pair)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<11 lines>...
for train, test in cv.split(X, y, **routed_params.splitter.split)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../site-packages/sklearn/utils/parallel.py", line 91, in __call__
return super().__call__(iterable_with_config_and_warning_filters)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/joblib/parallel.py", line 2012, in __call__
return output if self.return_generator else list(output)
~~~~^^^^^^^^
File ".../site-packages/joblib/parallel.py", line 1940, in _get_sequential_output
res = func(*args, **kwargs)
File ".../site-packages/sklearn/utils/parallel.py", line 184, in __call__
return self.function(*args, **kwargs)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File ".../site-packages/sklearn/calibration.py", line 661, in _fit_classifier_calibrator_pair
predictions, _ = _get_response_values(
~~~~~~~~~~~~~~~~~~~~^
estimator,
^^^^^^^^^^
X_test,
^^^^^^^
response_method=["decision_function", "predict_proba"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../site-packages/sklearn/utils/_response.py", line 215, in _get_response_values
y_pred = prediction_method(X)
File ".../site-packages/sklearn/pipeline.py", line 975, in decision_function
Xt = transform.transform(
Xt, **routed_params.get(name, {}).get("transform", {})
)
File ".../site-packages/sklearn/utils/_set_output.py", line 327, in wrapped
data_to_wrap = f(self, X, *args, **kwargs)
File "repro.py", line 22, in transform
raise ValueError("transform got no groups")
ValueError: transform got no groupsCalibratedClassifierCV(...).predict_proba(X, groups=groups) on a fitted model raises TypeError: CalibratedClassifierCV.predict_proba() got an unexpected keyword argument 'groups'.
Versions
System:
python: 3.13.17 (main, Oct 21 2026, 13:48:20) [Clang 21.0.0 (clang-2100.3.34.2)]
executable: .../coco-pipe/.venv/bin/python
machine: macOS-27.0.1-arm64-arm-64bit-Mach-O
Python dependencies:
sklearn: 1.9.1
pip: None
setuptools: 84.0.0
numpy: 2.5.4
scipy: 1.18.1
Cython: None
pandas: 3.0.6
matplotlib: 3.11.2
joblib: 1.6.0
threadpoolctl: 3.7.0
narwhals: 2.27.1
Built with OpenMP: True
threadpoolctl info:
user_api: openmp
internal_api: openmp
num_threads: 8
prefix: libomp
filepath: .../coco-pipe/.venv/lib/python3.13/site-packages/sklearn/.dylibs/libomp.dylib
version: NoneInterest in fixing the bug
I can open a PR: route fit to the estimator's response method for the held-out predictions, with each test fold's metadata, and let predict_proba/predict take **params. It could reuse the pattern of #35421.
Activity
waseem1302-x commentedon Nov 30, 2026
Hi, I reproduced this on current main. I cloned the repo, ran your script, and checked the fix direction with a local patch and tests.
The bug is real: with routing on,
CalibratedClassifierCV(pipe, cv=3).fit(X, y, groups=groups)fails withValueError: transform got no groups, because the held-out predictions get no metadata.predict_proba(X, groups=groups)fails too, it takes no extra arguments at all.The fix direction checks out. Routing the fit metadata to the estimator's response method, subset to each test fold, and letting
predict_proba/predicttake**paramsmakes your script pass for all three methods (sigmoid, isotonic, temperature) and bothensemble=TrueandFalse. I checked the same thing throughcross_val_predict, and the grouped-splitter case from #35523 (GroupKFoldwithensemble=False) works too once the splitter gets its groups. I added 119 tests for this; the full calibration suite passes and a plain estimator's probabilities are unchanged.Two review findings I fixed along the way: a TypeError caused by the weights themselves (for example weights with a bad value) was silently swallowed by the retry and returned unweighted results, now it raises. And
scoresilently droppedsample_weightwhen the response method requested it under an alias, now it forwards it under the alias name.Two details that matter: the metadata has to be subset to the test fold, not passed whole, and the router has to map
fitto bothpredict_probaanddecision_function, since the method used is only known once the estimator is fitted. One caveat: a custom estimator whose response methods accept the metadata has to set the request on both of them, even though only one is used.I am not opening a PR: the issue still has the Needs Triage label, and you said you can open one yourself.