Skip to content

Commit 76439b4

Browse files
authored
fix: *sklearn* version compability in stacking_cv params (#1124)
* fix: update parameter handling for sklearn version compatibility in stacking_cv * added fix to changelog * removed trailing whitespaces for flake8
1 parent 29e2fc4 commit 76439b4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/sources/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ The CHANGELOG for the current development version is available at
77

88
---
99

10+
##### Changes
11+
12+
- [`mlxtend/classifier/stacking_cv_classification.py`](https://github.com/rasbt/mlxtend/blob/master/mlxtend/classifier/stacking_cv_classification.py) and [`mlxtend/regressor/stacking_cv_regression.py`](https://github.com/rasbt/mlxtend/blob/master/mlxtend/regressor/stacking_cv_regression.py)
13+
- Modified `meta_features` to ensure compatibility with *scikit-learn* versions 1.4 and above by dynamically selecting between `fit_params` and `params` in `cross_val_predict`.
14+
1015
### Version 0.24.4 (25 Nov 2025)
1116

1217
##### Downloads

mlxtend/classifier/stacking_cv_classification.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import numpy as np
1313
from scipy import sparse
14+
from sklearn import __version__ as sklearn_version
1415
from sklearn.base import TransformerMixin, clone
1516
from sklearn.model_selection import cross_val_predict
1617
from sklearn.model_selection._split import check_cv
@@ -266,14 +267,15 @@ def fit(self, X, y, groups=None, sample_weight=None):
266267
if self.verbose > 1:
267268
print(_name_estimators((model,))[0][1])
268269

270+
param_name = "fit_params" if sklearn_version < "1.4" else "params"
269271
prediction = cross_val_predict(
270272
model,
271273
X,
272274
y,
273275
groups=groups,
274276
cv=final_cv,
275277
n_jobs=self.n_jobs,
276-
fit_params=fit_params,
278+
**{param_name: fit_params},
277279
verbose=self.verbose,
278280
pre_dispatch=self.pre_dispatch,
279281
method="predict_proba" if self.use_probas else "predict",

mlxtend/regressor/stacking_cv_regression.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import numpy as np
1717
from scipy import sparse
18+
from sklearn import __version__ as sklearn_version
1819
from sklearn.base import RegressorMixin, TransformerMixin, clone
1920
from sklearn.model_selection import cross_val_predict
2021
from sklearn.model_selection._split import check_cv
@@ -211,6 +212,7 @@ def fit(self, X, y, groups=None, sample_weight=None):
211212
fit_params = None
212213
else:
213214
fit_params = dict(sample_weight=sample_weight)
215+
param_name = "fit_params" if sklearn_version < "1.4" else "params"
214216
meta_features = np.column_stack(
215217
[
216218
cross_val_predict(
@@ -221,7 +223,7 @@ def fit(self, X, y, groups=None, sample_weight=None):
221223
cv=kfold,
222224
verbose=self.verbose,
223225
n_jobs=self.n_jobs,
224-
fit_params=fit_params,
226+
**{param_name: fit_params},
225227
pre_dispatch=self.pre_dispatch,
226228
)
227229
for regr in self.regr_

0 commit comments

Comments
 (0)