Skip to content

Commit bf260c4

Browse files
committed
Merge remote-tracking branch 'origin' into pr/fritshermans/1125
2 parents 1c642ce + 0780bc9 commit bf260c4

File tree

10 files changed

+9020
-9169
lines changed

10 files changed

+9020
-9169
lines changed

.github/workflows/linters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v4
18-
- uses: prefix-dev/[email protected].1
18+
- uses: prefix-dev/[email protected].14
1919
with:
20-
pixi-version: v0.39.2
20+
pixi-version: v0.51.0
2121
frozen: true
2222

2323
- name: Run tests

.github/workflows/tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
ci-py310-min-tensorflow,
2121
ci-py311-sklearn-1-4,
2222
ci-py311-sklearn-1-5,
23+
ci-py312-sklearn-1-6,
2324
ci-py311-latest-keras,
2425
ci-py311-latest-tensorflow,
2526
ci-py313-latest-dependencies,
@@ -37,9 +38,9 @@ jobs:
3738
runs-on: ${{ matrix.os }}
3839
steps:
3940
- uses: actions/checkout@v4
40-
- uses: prefix-dev/[email protected].1
41+
- uses: prefix-dev/[email protected].14
4142
with:
42-
pixi-version: v0.39.2
43+
pixi-version: v0.51.0
4344
environments: ${{ matrix.environment }}
4445
# we can freeze the environment and manually bump the dependencies to the
4546
# latest version time to time.
@@ -49,7 +50,7 @@ jobs:
4950
run: pixi run -e ${{ matrix.environment }} tests -n 3
5051

5152
- name: Upload coverage reports to Codecov
52-
uses: codecov/codecov-action@v5.1.2
53+
uses: codecov/codecov-action@v5.4.3
5354
with:
5455
token: ${{ secrets.CODECOV_TOKEN }}
5556
slug: scikit-learn-contrib/imbalanced-learn

doc/ensemble.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Bagging classifier
1919
In ensemble classifiers, bagging methods build several estimators on different
2020
randomly selected subset of data. In scikit-learn, this classifier is named
2121
:class:`~sklearn.ensemble.BaggingClassifier`. However, this classifier does not
22-
allow to balance each subset of data. Therefore, when training on imbalanced
22+
allow each subset of data to be balanced. Therefore, when training on an imbalanced
2323
data set, this classifier will favor the majority classes::
2424

2525
>>> from sklearn.datasets import make_classification
@@ -59,10 +59,10 @@ sampling is controlled by the parameter `sampler` or the two parameters
5959
>>> balanced_accuracy_score(y_test, y_pred)
6060
0.8...
6161

62-
Changing the `sampler` will give rise to different known implementation
62+
Changing the `sampler` will give rise to different known implementations
6363
:cite:`maclin1997empirical`, :cite:`hido2009roughly`,
64-
:cite:`wang2009diversity`. You can refer to the following example shows in
65-
practice these different methods:
64+
:cite:`wang2009diversity`. You can refer to the following example which shows these
65+
different methods in practice:
6666
:ref:`sphx_glr_auto_examples_ensemble_plot_bagging_classifier.py`
6767

6868
.. _forest:
@@ -93,7 +93,7 @@ Boosting
9393

9494
Several methods taking advantage of boosting have been designed.
9595

96-
:class:`RUSBoostClassifier` randomly under-sample the dataset before to perform
96+
:class:`RUSBoostClassifier` randomly under-samples the dataset before performing
9797
a boosting iteration :cite:`seiffert2009rusboost`::
9898

9999
>>> from imblearn.ensemble import RUSBoostClassifier
@@ -107,7 +107,7 @@ a boosting iteration :cite:`seiffert2009rusboost`::
107107

108108
A specific method which uses :class:`~sklearn.ensemble.AdaBoostClassifier` as
109109
learners in the bagging classifier is called "EasyEnsemble". The
110-
:class:`EasyEnsembleClassifier` allows to bag AdaBoost learners which are
110+
:class:`EasyEnsembleClassifier` allows bagging AdaBoost learners which are
111111
trained on balanced bootstrap samples :cite:`liu2008exploratory`. Similarly to
112112
the :class:`BalancedBaggingClassifier` API, one can construct the ensemble as::
113113

imblearn/ensemble/_easy_ensemble.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# License: MIT
66

77
import copy
8+
import inspect
89
import numbers
910

1011
import numpy as np
@@ -13,7 +14,6 @@
1314
from sklearn.ensemble._bagging import _parallel_decision_function
1415
from sklearn.ensemble._base import _partition_estimators
1516
from sklearn.utils._param_validation import Interval, StrOptions
16-
from sklearn.utils._tags import _safe_tags
1717
from sklearn.utils.fixes import parse_version
1818
from sklearn.utils.metaestimators import available_if
1919
from sklearn.utils.parallel import Parallel, delayed
@@ -312,11 +312,16 @@ def decision_function(self, X):
312312
# Parallel loop
313313
n_jobs, _, starts = _partition_estimators(self.n_estimators, self.n_jobs)
314314

315+
kwargs = {}
316+
if "params" in inspect.signature(_parallel_decision_function).parameters:
317+
kwargs["params"] = {}
318+
315319
all_decisions = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
316320
delayed(_parallel_decision_function)(
317321
self.estimators_[starts[i] : starts[i + 1]],
318322
self.estimators_features_[starts[i] : starts[i + 1]],
319323
X,
324+
**kwargs,
320325
)
321326
for i in range(n_jobs)
322327
)
@@ -343,7 +348,7 @@ def _get_estimator(self):
343348
return self.estimator
344349

345350
def _more_tags(self):
346-
return {"allow_nan": _safe_tags(self._get_estimator(), "allow_nan")}
351+
return {"allow_nan": get_tags(self._get_estimator()).input_tags.allow_nan}
347352

348353
def __sklearn_tags__(self):
349354
tags = super().__sklearn_tags__()

imblearn/keras/tests/test_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def data():
2424
X, y = make_imbalance(
2525
iris.data, iris.target, sampling_strategy={0: 30, 1: 50, 2: 40}
2626
)
27-
y = LabelBinarizer().fit_transform(y)
27+
X = X.astype(np.float32)
28+
y = LabelBinarizer().fit_transform(y).astype(np.int32)
2829
return X, y
2930

3031

@@ -103,7 +104,7 @@ def test_balanced_batch_generator_function_no_return_indices(data):
103104
(None, None),
104105
(RandomOverSampler(), None),
105106
(NearMiss(), None),
106-
(None, np.random.uniform(size=120)),
107+
(None, np.random.uniform(size=120).astype(np.float32)),
107108
],
108109
)
109110
def test_balanced_batch_generator_function(data, sampler, sample_weight):
@@ -117,6 +118,7 @@ def test_balanced_batch_generator_function(data, sampler, sample_weight):
117118
batch_size=10,
118119
random_state=42,
119120
)
121+
print(next(training_generator))
120122
model.fit(
121123
training_generator,
122124
steps_per_epoch=steps_per_epoch,

imblearn/metrics/tests/test_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def test_iba_error_y_score_prob_error(score_loss):
454454
y_true, y_pred, _ = make_prediction(binary=True)
455455

456456
aps = make_index_balanced_accuracy(alpha=0.5, squared=True)(score_loss)
457-
with pytest.raises(AttributeError):
457+
with pytest.raises((AttributeError, TypeError)):
458458
aps(y_true, y_pred)
459459

460460

imblearn/over_sampling/_smote/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,5 @@ def _more_tags(self):
981981

982982
def __sklearn_tags__(self):
983983
tags = super().__sklearn_tags__()
984-
tags.input_tags.sparse = False
985984
tags.input_tags.string = True
986985
return tags

imblearn/tests/test_pipeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from imblearn.pipeline import Pipeline, make_pipeline
4040
from imblearn.under_sampling import EditedNearestNeighbours as ENN
4141
from imblearn.under_sampling import RandomUnderSampler
42-
from imblearn.utils._sklearn_compat import sklearn_version
42+
from imblearn.utils._sklearn_compat import Tags, sklearn_version
4343
from imblearn.utils.estimator_checks import check_param_validation
4444

4545
JUNK_FOOD_DOCS = (
@@ -61,6 +61,9 @@ def __init__(self, a=None, b=None):
6161
self.a = a
6262
self.b = b
6363

64+
def __sklearn_tags__(self):
65+
return Tags()
66+
6467

6568
class NoTrans(NoFit):
6669
def fit(self, X, y):

0 commit comments

Comments
 (0)