Skip to content

Commit

Permalink
MAINT cosmetic follow-up switch pixi + GitHub Actions (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
glemaitre authored Oct 6, 2024
1 parent 4d4cfd3 commit b56b346
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 620 deletions.
22 changes: 19 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

.. _scikit-learn-contrib: https://github.com/scikit-learn-contrib

|Azure|_ |Codecov|_ |CircleCI|_ |PythonVersion|_ |Pypi|_ |Gitter|_ |Black|_
|GitHubActions|_ |Codecov|_ |CircleCI|_ |PythonVersion|_ |Pypi|_ |Gitter|_ |Black|_

.. |Azure| image:: https://dev.azure.com/imbalanced-learn/imbalanced-learn/_apis/build/status/scikit-learn-contrib.imbalanced-learn?branchName=master
.. _Azure: https://dev.azure.com/imbalanced-learn/imbalanced-learn/_build
.. |GitHubActions| image:: https://github.com/scikit-learn-contrib/imbalanced-learn/actions/workflows/tests.yml/badge.svg
.. _GitHubActions: https://github.com/scikit-learn-contrib/imbalanced-learn/actions/workflows/tests.yml

.. |Codecov| image:: https://codecov.io/gh/scikit-learn-contrib/imbalanced-learn/branch/master/graph/badge.svg
.. _Codecov: https://codecov.io/gh/scikit-learn-contrib/imbalanced-learn
Expand Down Expand Up @@ -66,6 +66,7 @@ Dependencies
- NumPy (>= |NumPyMinVersion|)
- SciPy (>= |SciPyMinVersion|)
- Scikit-learn (>= |ScikitLearnMinVersion|)
- Pytest (>= |PytestMinVersion|)

Additionally, `imbalanced-learn` requires the following optional dependencies:

Expand Down Expand Up @@ -128,6 +129,21 @@ of the scikit-learn community. Therefore, you can refer to their
`Development Guide
<http://scikit-learn.org/stable/developers>`_.

Endorsement of the Scientific Python Specification
--------------------------------------------------

We endorse good practices from the Scientific Python Ecosystem Coordination (SPEC).
The full list of recommendations is available `here`_.

See below the list of recommendations that we endorse for the imbalanced-learn project.

|SPEC 0 — Minimum Supported Dependencies|

.. |SPEC 0 — Minimum Supported Dependencies| image:: https://img.shields.io/badge/SPEC-0-green?labelColor=%23004811&color=%235CA038
:target: https://scientific-python.org/specs/spec-0000/

.. _here: https://scientific-python.org/specs/

About
-----

Expand Down
61 changes: 0 additions & 61 deletions imblearn/_min_dependencies.py

This file was deleted.

13 changes: 1 addition & 12 deletions imblearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,14 @@
from abc import ABCMeta, abstractmethod

import numpy as np
import sklearn
from sklearn.base import BaseEstimator

try:
# scikit-learn >= 1.2
from sklearn.base import OneToOneFeatureMixin
except ImportError:
from sklearn.base import _OneToOneFeatureMixin as OneToOneFeatureMixin

from sklearn.base import BaseEstimator, OneToOneFeatureMixin
from sklearn.preprocessing import label_binarize
from sklearn.utils.fixes import parse_version
from sklearn.utils.multiclass import check_classification_targets

from .utils import check_sampling_strategy, check_target_type
from .utils._param_validation import validate_parameter_constraints
from .utils._validation import ArraysTransformer

sklearn_version = parse_version(sklearn.__version__)


class _ParamsValidationMixin:
"""Mixin class to validate parameters."""
Expand Down
42 changes: 2 additions & 40 deletions imblearn/ensemble/_bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@

import copy
import numbers
import warnings

import numpy as np
import sklearn
from sklearn.base import clone
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble._bagging import _parallel_decision_function
from sklearn.ensemble._base import _partition_estimators
from sklearn.exceptions import NotFittedError
from sklearn.tree import DecisionTreeClassifier
from sklearn.utils.fixes import parse_version
from sklearn.utils.metaestimators import available_if
from sklearn.utils.parallel import Parallel, delayed
from sklearn.utils.validation import check_is_fitted

try:
# scikit-learn >= 1.2
from sklearn.utils.parallel import Parallel, delayed
except (ImportError, ModuleNotFoundError):
from joblib import Parallel
from sklearn.utils.fixes import delayed

from ..base import _ParamsValidationMixin
from ..pipeline import Pipeline
from ..under_sampling import RandomUnderSampler
from ..under_sampling.base import BaseUnderSampler
from ..utils import Substitution, check_sampling_strategy, check_target_type
from ..utils._available_if import available_if
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
from ..utils._param_validation import HasMethods, Interval, StrOptions
from ..utils.fixes import _fit_context
Expand Down Expand Up @@ -128,14 +120,6 @@ class BalancedBaggingClassifier(_ParamsValidationMixin, BaggingClassifier):
.. versionadded:: 0.10
n_features_ : int
The number of features when `fit` is performed.
.. deprecated:: 1.0
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
in version 1.2. When the minimum version of `scikit-learn` supported
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
estimators_ : list of estimators
The collection of fitted base estimators.
Expand Down Expand Up @@ -338,20 +322,6 @@ def _validate_estimator(self, default=DecisionTreeClassifier()):
[("sampler", self.sampler_), ("classifier", estimator)]
)

# TODO: remove when supporting scikit-learn>=1.2
@property
def n_features_(self):
"""Number of features when ``fit`` is performed."""
warnings.warn(
(
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
"not be accessible when the minimum supported version of scikit-learn "
"is 1.2."
),
FutureWarning,
)
return self.n_features_in_

@_fit_context(prefer_skip_nested_validation=False)
def fit(self, X, y):
"""Build a Bagging ensemble of estimators from the training set (X, y).
Expand Down Expand Up @@ -443,14 +413,6 @@ def base_estimator_(self):
error = AttributeError(
f"{self.__class__.__name__} object has no attribute 'base_estimator_'."
)
if sklearn_version < parse_version("1.2"):
# The base class require to have the attribute defined. For scikit-learn
# > 1.2, we are going to raise an error.
try:
check_is_fitted(self)
return self.estimator_
except NotFittedError:
raise error
raise error

def _more_tags(self):
Expand Down
27 changes: 2 additions & 25 deletions imblearn/ensemble/_easy_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,17 @@
from sklearn.ensemble import AdaBoostClassifier, BaggingClassifier
from sklearn.ensemble._bagging import _parallel_decision_function
from sklearn.ensemble._base import _partition_estimators
from sklearn.exceptions import NotFittedError
from sklearn.utils._tags import _safe_tags
from sklearn.utils.fixes import parse_version
from sklearn.utils.metaestimators import available_if
from sklearn.utils.parallel import Parallel, delayed
from sklearn.utils.validation import check_is_fitted

try:
# scikit-learn >= 1.2
from sklearn.utils.parallel import Parallel, delayed
except (ImportError, ModuleNotFoundError):
from joblib import Parallel
from sklearn.utils.fixes import delayed

from ..base import _ParamsValidationMixin
from ..pipeline import Pipeline
from ..under_sampling import RandomUnderSampler
from ..under_sampling.base import BaseUnderSampler
from ..utils import Substitution, check_sampling_strategy, check_target_type
from ..utils._available_if import available_if
from ..utils._docstring import _n_jobs_docstring, _random_state_docstring
from ..utils._param_validation import Interval, StrOptions
from ..utils.fixes import _fit_context
Expand Down Expand Up @@ -107,14 +100,6 @@ class EasyEnsembleClassifier(_ParamsValidationMixin, BaggingClassifier):
n_classes_ : int or list
The number of classes.
n_features_ : int
The number of features when `fit` is performed.
.. deprecated:: 1.0
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
in version 1.2. When the minimum version of `scikit-learn` supported
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
n_features_in_ : int
Number of features in the input dataset.
Expand Down Expand Up @@ -357,14 +342,6 @@ def base_estimator_(self):
error = AttributeError(
f"{self.__class__.__name__} object has no attribute 'base_estimator_'."
)
if sklearn_version < parse_version("1.2"):
# The base class require to have the attribute defined. For scikit-learn
# > 1.2, we are going to raise an error.
try:
check_is_fitted(self)
return self.estimator_
except NotFittedError:
raise error
raise error

def _get_estimator(self):
Expand Down
52 changes: 5 additions & 47 deletions imblearn/ensemble/_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@
from sklearn.utils import _safe_indexing, check_random_state
from sklearn.utils.fixes import parse_version
from sklearn.utils.multiclass import type_of_target
from sklearn.utils.parallel import Parallel, delayed
from sklearn.utils.validation import _check_sample_weight

try:
# scikit-learn >= 1.2
from sklearn.utils.parallel import Parallel, delayed
except (ImportError, ModuleNotFoundError):
from joblib import Parallel
from sklearn.utils.fixes import delayed

from ..base import _ParamsValidationMixin
from ..pipeline import make_pipeline
from ..under_sampling import RandomUnderSampler
Expand Down Expand Up @@ -80,6 +74,7 @@ def _local_parallel_build_trees(
"verbose": verbose,
"class_weight": class_weight,
"n_samples_bootstrap": n_samples_bootstrap,
"bootstrap": bootstrap,
}

if parse_version(sklearn_version.base_version) >= parse_version("1.4"):
Expand All @@ -89,13 +84,6 @@ def _local_parallel_build_trees(
missing_values_in_feature_mask
)

# TODO: remove when the minimum supported version of scikit-learn will be 1.1
# change of signature in scikit-learn 1.1
if parse_version(sklearn_version.base_version) >= parse_version("1.1"):
params_parallel_build_trees["bootstrap"] = bootstrap
else:
params_parallel_build_trees["forest"] = forest

tree = _parallel_build_trees(**params_parallel_build_trees)

return sampler, tree
Expand Down Expand Up @@ -355,14 +343,6 @@ class labels (multi-output problem).
The number of classes (single output problem), or a list containing the
number of classes for each output (multi-output problem).
n_features_ : int
The number of features when `fit` is performed.
.. deprecated:: 1.0
`n_features_` is deprecated in `scikit-learn` 1.0 and will be removed
in version 1.2. When the minimum version of `scikit-learn` supported
by `imbalanced-learn` will reach 1.2, this attribute will be removed.
n_features_in_ : int
Number of features in the input dataset.
Expand Down Expand Up @@ -514,13 +494,8 @@ def __init__(
def _validate_estimator(self, default=DecisionTreeClassifier()):
"""Check the estimator and the n_estimator attribute, set the
`estimator_` attribute."""
if hasattr(self, "estimator"):
base_estimator = self.estimator
else:
base_estimator = self.base_estimator

if base_estimator is not None:
self.estimator_ = clone(base_estimator)
if self.estimator is not None:
self.estimator_ = clone(self.estimator)
else:
self.estimator_ = clone(default)

Expand Down Expand Up @@ -905,22 +880,5 @@ def _compute_oob_predictions(self, X, y):

return oob_pred

# TODO: remove when supporting scikit-learn>=1.2
@property
def n_features_(self):
"""Number of features when ``fit`` is performed."""
warn(
(
"`n_features_` was deprecated in scikit-learn 1.0. This attribute will "
"not be accessible when the minimum supported version of scikit-learn "
"is 1.2."
),
FutureWarning,
)
return self.n_features_in_

def _more_tags(self):
return {
"multioutput": False,
"multilabel": False,
}
return {"multioutput": False, "multilabel": False}
Loading

0 comments on commit b56b346

Please sign in to comment.