Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most recent scikit-learn results in several failed unit tests #1091

Merged
merged 16 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
conda install tensorflow joblib pytest -y -q
conda install imageio scikit-image -y -q
conda install dlib -y -q
pip install scikit-learn==1.1.3 pandas==1.3.5 markdown coverage
pip install scikit-learn==1.3.1 pandas==1.3.5 markdown coverage
pip install -e .
python -c "import numpy; print('NumPy:', numpy.__version__)"
python -c "import scipy; print('SciPy:', scipy.__version__)"
Expand Down
14 changes: 14 additions & 0 deletions docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ The CHANGELOG for the current development version is available at

---

### Version 0.23.2 (TBD)

##### Downloads

- [Source code (zip)](https://github.com/rasbt/mlxtend/archive/v0.23.2.zip)

- [Source code (tar.gz)](https://github.com/rasbt/mlxtend/archive/v0.23.2.tar.gz)

##### Changes

- Add `n_classes_` attribute to stacking classifiers for compatibility with scikit-learn 1.3 ([#1091](https://github.com/rasbt/mlxtend/issues/1091)



### Version 0.23.1 (5 Jan 2024)

##### Downloads
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- pandas>=1.3.4
- pip>=21.3.1
- pytest>=6.2.5
- scikit-learn>=1.0.1
- scikit-learn>=1.3.1
- scipy>=1.7.3
- setuptools>=59.4.0
- pip:
Expand Down
2 changes: 1 addition & 1 deletion mlxtend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#
# License: BSD 3 clause

__version__ = "0.23.1"
__version__ = "0.23.2dev"
11 changes: 11 additions & 0 deletions mlxtend/classifier/stacking_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
from scipy import sparse
from sklearn.base import TransformerMixin, clone
from sklearn.preprocessing import LabelEncoder

from ..externals.estimator_checks import check_is_fitted
from ..externals.name_estimators import _name_estimators
Expand Down Expand Up @@ -95,6 +96,9 @@ class StackingClassifier(_BaseXComposition, _BaseStackingClassifier, Transformer
Fitted classifiers (clones of the original classifiers)
meta_clf_ : estimator
Fitted meta-classifier (clone of the original meta-estimator)
classes_ : ndarray of shape (n_classes,) or list of ndarray if `y` \
is of type `"multilabel-indicator"`.
Class labels.
train_meta_features : numpy array, shape = [n_samples, n_classifiers]
meta-features for training data, where n_samples is the
number of samples
Expand Down Expand Up @@ -175,6 +179,13 @@ def fit(self, X, y, sample_weight=None):
self.clfs_ = self.classifiers
self.meta_clf_ = self.meta_classifier

if y.ndim > 1:
self._label_encoder = [LabelEncoder().fit(yk) for yk in y.T]
self.classes_ = [le.classes_ for le in self._label_encoder]
else:
self._label_encoder = LabelEncoder().fit(y)
self.classes_ = self._label_encoder.classes_

if self.fit_base_estimators:
if self.verbose > 0:
print("Fitting %d classifiers..." % (len(self.classifiers)))
Expand Down
11 changes: 11 additions & 0 deletions mlxtend/classifier/stacking_cv_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sklearn.base import TransformerMixin, clone
from sklearn.model_selection import cross_val_predict
from sklearn.model_selection._split import check_cv
from sklearn.preprocessing import LabelEncoder

from ..externals.estimator_checks import check_is_fitted
from ..externals.name_estimators import _name_estimators
Expand Down Expand Up @@ -129,6 +130,9 @@ class StackingCVClassifier(
Fitted classifiers (clones of the original classifiers)
meta_clf_ : estimator
Fitted meta-classifier (clone of the original meta-estimator)
classes_ : ndarray of shape (n_classes,) or list of ndarray if `y` \
is of type `"multilabel-indicator"`.
Class labels.
train_meta_features : numpy array, shape = [n_samples, n_classifiers]
meta-features for training data, where n_samples is the
number of samples
Expand Down Expand Up @@ -220,6 +224,13 @@ def fit(self, X, y, groups=None, sample_weight=None):
if self.verbose > 0:
print("Fitting %d classifiers..." % (len(self.classifiers)))

if y.ndim > 1:
self._label_encoder = [LabelEncoder().fit(yk) for yk in y.T]
self.classes_ = [le.classes_ for le in self._label_encoder]
else:
self._label_encoder = LabelEncoder().fit(y)
self.classes_ = self._label_encoder.classes_

final_cv = check_cv(self.cv, y, classifier=self.stratify)
if isinstance(self.cv, int):
# Override shuffle parameter in case of self generated
Expand Down
2 changes: 1 addition & 1 deletion mlxtend/classifier/tests/test_stacking_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def test_decision_function():
if Version(sklearn_version) < Version("0.22"):
assert scores_mean == 0.95, scores_mean
else:
assert scores_mean == 0.94, scores_mean
assert scores_mean == 0.93, scores_mean


def test_drop_col_unsupported():
Expand Down
4 changes: 1 addition & 3 deletions mlxtend/preprocessing/tests/test_transactionencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def test_fit_transform():
def test_inverse_transform():
oht = TransactionEncoder()
oht.fit(dataset)
np.testing.assert_array_equal(
np.array(data_sorted), np.array(oht.inverse_transform(expect))
)
assert data_sorted == oht.inverse_transform(expect)


def test_cloning():
Expand Down
1 change: 1 addition & 0 deletions mlxtend/regressor/tests/test_stacking_cv_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def test_weight_unsupported_with_no_weight():
stack.fit(X1, y).predict(X1)


@pytest.mark.skip(reason="scikit-learn implemented a StackingRegressor in 0.22.")
def test_gridsearch_replace_mix():
svr_lin = SVR(kernel="linear", gamma="auto")
ridge = Ridge(random_state=1)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
scipy>=1.2.1
numpy>=1.16.2
pandas>=0.24.2
scikit-learn>=1.0.2
scikit-learn>=1.3.1
matplotlib>=3.0.0
joblib>=0.13.2
Loading