···
1
+
From 1fb59eb42f4bef229b953de313c7e78f0857ea42 Mon Sep 17 00:00:00 2001
2
+
From: Philip Wilk <p.wilk@student.reading.ac.uk>
3
+
Date: Sun, 23 Mar 2025 16:14:51 +0000
4
+
Subject: [PATCH] StackingCVClassifier/fit: ensure compatibility with
5
+
*scikit-learn* versions 1.4 and above by dynamically selecting between
6
+
`fit_params` and `params`
9
+
mlxtend/classifier/stacking_cv_classification.py | 5 ++++-
10
+
mlxtend/regressor/stacking_cv_regression.py | 6 +++++-
11
+
2 files changed, 9 insertions(+), 2 deletions(-)
13
+
diff --git a/mlxtend/classifier/stacking_cv_classification.py b/mlxtend/classifier/stacking_cv_classification.py
14
+
index 5bff6907..f4c45b8c 100644
15
+
--- a/mlxtend/classifier/stacking_cv_classification.py
16
+
+++ b/mlxtend/classifier/stacking_cv_classification.py
17
+
@@ -15,6 +15,7 @@ from sklearn.base import TransformerMixin, clone
18
+
from sklearn.model_selection import cross_val_predict
19
+
from sklearn.model_selection._split import check_cv
20
+
from sklearn.preprocessing import LabelEncoder
21
+
+from sklearn import __version__ as sklearn_version
23
+
from ..externals.estimator_checks import check_is_fitted
24
+
from ..externals.name_estimators import _name_estimators
25
+
@@ -266,6 +267,8 @@ class StackingCVClassifier(
26
+
if self.verbose > 1:
27
+
print(_name_estimators((model,))[0][1])
29
+
+ param_name = "fit_params" if sklearn_version < "1.4" else "params"
31
+
prediction = cross_val_predict(
34
+
@@ -273,10 +276,10 @@ class StackingCVClassifier(
38
+
- fit_params=fit_params,
39
+
verbose=self.verbose,
40
+
pre_dispatch=self.pre_dispatch,
41
+
method="predict_proba" if self.use_probas else "predict",
42
+
+ **{param_name: fit_params},
45
+
if not self.use_probas:
46
+
diff --git a/mlxtend/regressor/stacking_cv_regression.py b/mlxtend/regressor/stacking_cv_regression.py
47
+
index a1faf2ff..d2fb1c49 100644
48
+
--- a/mlxtend/regressor/stacking_cv_regression.py
49
+
+++ b/mlxtend/regressor/stacking_cv_regression.py
50
+
@@ -19,6 +19,7 @@ from sklearn.base import RegressorMixin, TransformerMixin, clone
51
+
from sklearn.model_selection import cross_val_predict
52
+
from sklearn.model_selection._split import check_cv
53
+
from sklearn.utils import check_X_y
54
+
+from sklearn import __version__ as sklearn_version
56
+
from ..externals.estimator_checks import check_is_fitted
57
+
from ..externals.name_estimators import _name_estimators
58
+
@@ -211,6 +212,9 @@ class StackingCVRegressor(_BaseXComposition, RegressorMixin, TransformerMixin):
61
+
fit_params = dict(sample_weight=sample_weight)
63
+
+ param_name = "fit_params" if sklearn_version < "1.4" else "params"
65
+
meta_features = np.column_stack(
68
+
@@ -221,8 +225,8 @@ class StackingCVRegressor(_BaseXComposition, RegressorMixin, TransformerMixin):
70
+
verbose=self.verbose,
72
+
- fit_params=fit_params,
73
+
pre_dispatch=self.pre_dispatch,
74
+
+ **{param_name: fit_params},
76
+
for regr in self.regr_