10000 MAINT compatibility with scikit-learn 0.22 by glemaitre · Pull Request #617 · scikit-learn-contrib/imbalanced-learn · GitHub
[go: up one dir, main page]

Skip to content

MAINT compatibility with scikit-learn 0.22 #617

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

Merged
merged 37 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9d499fe
DOC issue compiling documentation
glemaitre Oct 29, 2019
b2c1d49
iter
glemaitre Oct 29, 2019
0dddad4
iter
glemaitre Oct 29, 2019
c13add1
iter
glemaitre Oct 29, 2019
d3e3770
iter
glemaitre Oct 29, 2019
f326765
iter
glemaitre Oct 29, 2019
bb9e69b
iter
glemaitre Oct 29, 2019
3dcbb4a
iter
glemaitre Oct 29, 2019
702f092
iter
glemaitre Oct 30, 2019
d58cf2f
iter
glemaitre Oct 30, 2019
7e6df7b
iter
glemaitre Oct 30, 2019
3397810
change import which are breaking with sklearn master
glemaitre Oct 31, 2019
a03be26
fix in forest
glemaitre Oct 31, 2019
f2b8a27
MAINT remove EasyEnsemble and BalancedCascade
glemaitre Oct 31, 2019
32c7115
MAINT remove check_ratio
glemaitre Oct 31, 2019
da1265d
MAINT remove ratio after deprecation
glemaitre Oct 31, 2019
c3dccbb
MAINT remove check_ratio
glemaitre Oct 31, 2019
fdaf152
DEPR remove return_indices
glemaitre Oct 31, 2019
0e4a665
FIX SMOTE
glemaitre Oct 31, 2019
23076ea
DEPR remove random_state
glemaitre Oct 31, 2019
449c3b1
iter
glemaitre Oct 31, 2019
78a43b7
black
glemaitre Oct 31, 2019
f582182
flake8
glemaitre Oct 31, 2019
171d361
iter
glemaitre Oct 31, 2019
dfb54bf
remove warning
glemaitre Oct 31, 2019
46ba016
allow failure ubuntu
glemaitre Oct 31, 2019
7fea797
last warning
glemaitre Oct 31, 2019
263ff72
iter
glemaitre Oct 31, 2019
c5ac35d
iter
glemaitre Oct 31, 2019
c5a60a1
update ubuntu image
glemaitre Oct 31, 2019
54a2e92
iter
glemaitre Oct 31, 2019
05aaa8a
update example
glemaitre Oct 31, 2019
e31c6c6
TST only for tensorflow1
glemaitre Oct 31, 2019
d5b9ca8
xxx
glemaitre Oct 31, 2019
3a570b7
update appveyor
glemaitre Oct 31, 2019
3603cdf
update version of documentation for readthedocs
glemaitre Oct 31, 2019
034270f
documentation
glemaitre Oct 31, 2019
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 .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ formats:
- none
requirements_file: requirements.txt
python:
version: 3.6
version: 3.7
pip_install: true
extra_requirements:
- tests
Expand Down
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# make it explicit that we favor the new container-based travis workers
dist: xenial
dist: bionic
sudo: false

language: python
Expand Down Expand Up @@ -32,16 +32,12 @@ matrix:
# Ubuntu 14.04 environment
- env: DISTRIB="ubuntu"
# Latest release
- env: DISTRIB="conda" PYTHON_VERSION="3.6"
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="0.21.2"
OPTIONAL_DEPS="true"
- env: DISTRIB="conda" PYTHON_VERSION="3.7"
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="0.21.2"
OPTIONAL_DEPS="false"
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="master"
OPTIONAL_DEPS="keras"
- env: DISTRIB="conda" PYTHON_VERSION="3.7"
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="master"
OPTIONAL_DEPS="false"
allow_failures:
OPTIONAL_DEPS="tensorflow"
- env: DISTRIB="conda" PYTHON_VERSION="3.7"
NUMPY_VERSION="*" SCIPY_VERSION="*" SKLEARN_VERSION="master"
OPTIONAL_DEPS="false"
Expand Down
7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ Below is a list of the methods currently implemented in this module.
2. SMOTE + ENN [11]_

* Ensemble classifier using samplers internally
1. EasyEnsemble [13]_
2. BalanceCascade [13]_
3. Balanced Random Forest [16]_
4. Balanced Bagging
1. Easy Ensemble classifier [13]_
2. Balanced Random Forest [16]_
3. Balanced Bagging

The different algorithms are presented in the sphinx-gallery_.

Expand Down
11 changes: 8 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ environment:
- PYTHON: "C:\\Miniconda36-x64"
PYTHON_VERSION: "3.6"
PYTHON_ARCH: "64"
OPTIONAL_DEP: "pandas keras tensorflow"
OPTIONAL_DEP: "pandas keras tensorflow=1"

- PYTHON: "C:\\Miniconda36-x64"
PYTHON_VERSION: "3.6"
PYTHON_ARCH: "64"
OPTIONAL_DEP: "pandas tensorflow"

- PYTHON: "C:\\Miniconda36-x64"
PYTHON_VERSION: "3.7"
Expand All @@ -30,8 +35,8 @@ install:
- conda update conda -y -q
- conda create -n testenv --yes python=%PYTHON_VERSION% pip
- activate testenv
- conda install scipy numpy -y -q
- conda install scikit-learn -y -q
- conda install scipy numpy joblib -y -q
- pip install --pre -f https://sklearn-nightly.scdn8.secure.raxcdn.com scikit-learn
- conda install %OPTIONAL_DEP% -y -q
- conda install pytest pytest-cov -y -q
- pip install codecov
Expand Down
9 changes: 5 additions & 4 deletions build_tools/circle/build_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ conda update --yes --quiet conda

# Configure the conda environment and put it in the path using the
# provided versions
conda create -n $CONDA_ENV_NAME --yes --quiet python=3.6
conda create -n $CONDA_ENV_NAME --yes --quiet python=3.7
source activate $CONDA_ENV_NAME

conda install --yes pip numpy scipy pillow matplotlib sphinx \
sphinx_rtd_theme numpydoc pandas keras
pip install --pre scikit-learn
conda install --yes pip numpy scipy joblib pillow matplotlib sphinx \
memory_profiler sphinx_rtd_theme pandas keras tensorflow=1
pip install --pre -f https://sklearn-nightly.scdn8.secure.raxcdn.com scikit-learn
pip install -U git+https://github.com/sphinx-gallery/sphinx-gallery.git
pip install -U git+https://github.com/numpy/numpydoc.git

# Build and install imbalanced-learn in dev mode
ls -l
Expand Down
17 changes: 7 additions & 10 deletions build_tools/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,24 @@ if [[ "$DISTRIB" == "conda" ]]; then
MINICONDA_PATH=/home/travis/miniconda
chmod +x miniconda.sh && ./miniconda.sh -b -p $MINICONDA_PATH
export PATH=$MINICONDA_PATH/bin:$PATH
conda config --set always_yes yes --set changeps1 no
conda install conda=4.6
conda update -q conda
conda info -a

# Configure the conda environment and put it in the path using the
# provided versions
conda create -n testenv --yes python=$PYTHON_VERSION pip
source activate testenv
conda install --yes numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION

if [[ "$OPTIONAL_DEPS" == "true" ]]; then
conda install --yes pandas keras tensorflow
if [[ "$OPTIONAL_DEPS" == "keras" ]]; then
conda install --yes pandas keras tensorflow=1
KERAS_BACKEND=tensorflow
python -c "import keras.backend"
sed -i -e 's/"backend":[[:space:]]*"[^"]*/"backend":\ "'$KERAS_BACKEND'/g' ~/.keras/keras.json;
elif [[ "$OPTIONAL_DEPS" == "tensorflow" ]]; then
conda install --yes pandas tensorflow
fi

if [[ "$SKLEARN_VERSION" == "master" ]]; then
conda install --yes cython
pip install -U git+https://github.com/scikit-learn/scikit-learn.git
pip install --pre -f https://sklearn-nightly.scdn8.secure.raxcdn.com scikit-learn
else
conda install --yes scikit-learn=$SKLEARN_VERSION
fi
Expand All @@ -65,8 +62,8 @@ elif [[ "$DISTRIB" == "ubuntu" ]]; then
virtualenv --system-site-packages --python=python3 testvenv
source testvenv/bin/activate

pip3 install scikit-learn
pip3 install pandas keras tensorflow
pip install --pre -f https://sklearn-nightly.scdn8.secure.raxcdn.com scikit-learn
pip3 install pandas
pip3 install pytest pytest-cov codecov sphinx numpydoc

fi
Expand Down
3 changes: 0 additions & 3 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ Prototype selection
:toctree: generated/
:template: class.rst

ensemble.BalanceCascade
ensemble.BalancedBaggingClassifier
ensemble.BalancedRandomForestClassifier
ensemble.EasyEnsemble
ensemble.EasyEnsembleClassifier
ensemble.RUSBoostClassifier

Expand Down Expand Up @@ -251,5 +249,4 @@ Imbalance-learn provides some fast-prototyping tools.

utils.estimator_checks.check_estimator
utils.check_neighbors_object
utils.check_ratio
utils.check_sampling_strategy
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
sphinx_gallery_conf = {
'doc_module': 'imblearn',
'backreferences_dir': os.path.join('generated'),
'show_memory': True,
'reference_url': {
'imblearn': None}
}
Expand Down
43 changes: 43 additions & 0 deletions doc/whats_new/v0.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,46 @@ Version 0.6.0 (under-development)
Changelog
---------

Changed models
..............

The following models might give some different sampling due to changes in
scikit-learn:

- :class:`imblearn.under_sampling.ClusterCentroid`
- :class:`imblearn.under_sampling.InstanceHardnessThreshold`

Maintenance
...........

- Update imports from scikit-learn after that some modules have been privatize.
The following import have been changed:
:class:`sklearn.ensemble._base._set_random_states`,
:class:`sklearn.ensemble._forest._parallel_build_trees`,
:class:`sklearn.metrics._classification._check_targets`,
:class:`sklearn.metrics._classification._prf_divide`,
:class:`sklearn.utils.Bunch`,
:class:`sklearn.utils._safe_indexing`,
:class:`sklearn.utils._testing.assert_allclose`,
:class:`sklearn.utils._testing.assert_array_equal`,
:class:`sklearn.utils._testing.SkipTest`.
:pr:`617` by :user:`Guillaume Lemaitre <glemaitre>`.

Deprecation
...........

- The following classes have been removed after 2 deprecation cycles:
`ensemble.BalanceCascade` and `ensemble.EasyEnsemble`.
:pr:`617` by :user:`Guillaume Lemaitre <glemaitre>`.

- The following functions have been removed after 2 deprecation cycles:
`utils.check_ratio`.
:pr:`617` by :user:`Guillaume Lemaitre <glemaitre>`.

- The parameter `ratio` and `return_indices` has been removed from all
samplers.
:pr:`617` by :user:`Guillaume Lemaitre <glemaitre>`.

- The parameters `m_neighbors`, `out_step`, `kind`, `svm_estimator`
have been removed from the :class:`imblearn.over_sampling.SMOTE`.
:pr:`617` by :user:`Guillaume Lemaitre <glemaitre>`.
13 changes: 5 additions & 8 deletions examples/ensemble/plot_comparison_ensemble_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ def plot_confusion_matrix(cm, classes, ax,
# will use a bagging classifier and its counter part which internally uses a
# random under-sampling to balanced each boostrap sample.

bagging = BaggingClassifier(n_estimators=50, random_state=0, n_jobs=-1)
balanced_bagging = BalancedBaggingClassifier(n_estimators=50, random_state=0,
n_jobs=-1)
bagging = BaggingClassifier(n_estimators=50, random_state=0)
balanced_bagging = BalancedBaggingClassifier(n_estimators=50, random_state=0)

bagging.fit(X_train, y_train)
balanced_bagging.fit(X_train, y_train)
Expand Down Expand Up @@ -149,9 +148,8 @@ def plot_confusion_matrix(cm, classes, ax,
# outperforming bagging. Here, we used a vanilla random forest and its balanced
# counterpart in which each bootstrap sample is balanced.

rf = RandomForestClassifier(n_estimators=50, random_state=0, n_jobs=-1)
brf = BalancedRandomForestClassifier(n_estimators=50, random_state=0,
n_jobs=-1)
rf = RandomForestClassifier(n_estimators=50, random_state=0)
brf = BalancedRandomForestClassifier(n_estimators=50, random_state=0)

rf.fit(X_train, y_train)
brf.fit(X_train, y_train)
Expand Down Expand Up @@ -189,8 +187,7 @@ def plot_confusion_matrix(cm, classes, ax,

base_estimator = AdaBoostClassifier(n_estimators=10)
eec = EasyEnsembleClassifier(n_estimators=10,
base_estimator=base_estimator,
n_jobs=-1)
base_estimator=base_estimator)
eec.fit(X_train, y_train)
y_pred_eec = eec.predict(X_test)
print('Easy ensemble classifier performance:')
Expand Down
17 changes: 14 additions & 3 deletions 10000 imblearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
from ._version import __version__
from .utils._show_versions import show_versions

__all__ = ['combine', 'ensemble', 'exceptions', 'keras', 'metrics',
'over_sampling', 'tensorflow', 'under_sampling',
'utils', 'pipeline', 'FunctionSampler', '__version__']
__all__ = [
"combine",
"ensemble",
"exceptions",
"keras",
"metrics",
"over_sampling",
"tensorflow",
"under_sampling",
"utils",
"pipeline",
"FunctionSampler",
"__version__",
]
2 changes: 1 addition & 1 deletion imblearn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
#

__version__ = '0.6.0.dev0'
__version__ = "0.6.0.dev0"
40 changes: 11 additions & 29 deletions imblearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Christos Aridas
# License: MIT

import warnings
from abc import ABCMeta, abstractmethod

import numpy as np
Expand All @@ -15,7 +14,6 @@
from sklearn.utils.multiclass import check_classification_targets

from .utils import check_sampling_strategy, check_target_type
from .utils.deprecation import deprecate_parameter


class SamplerMixin(BaseEstimator, metaclass=ABCMeta):
Expand All @@ -25,7 +23,7 @@ class SamplerMixin(BaseEstimator, metaclass=ABCMeta):
instead.
"""

_estimator_type = 'sampler'
_estimator_type = "sampler"

def fit(self, X, y):
"""Check inputs and statistics of the sampler.
Expand All @@ -46,10 +44,10 @@ def fit(self, X, y):
Return the instance itself.

"""
self._deprecate_ratio()
X, y, _ = self._check_X_y(X, y)
self.sampling_strategy_ = check_sampling_strategy(
self.sampling_strategy, y, self._sampling_type)
self.sampling_strategy, y, self._sampling_type
)
return self

def fit_resample(self, X, y):
Expand All @@ -73,13 +71,12 @@ def fit_resample(self, X, y):
The corresponding label of `X_resampled`.

"""
self._deprecate_ratio()

check_classification_targets(y)
X, y, binarize_y = self._check_X_y(X, y)

self.sampling_strategy_ = check_sampling_strategy(
self.sampling_strategy, y, self._sampling_type)
self.sampling_strategy, y, self._sampling_type
)

output = self._fit_resample(X, y)

Expand Down Expand Up @@ -126,31 +123,15 @@ class BaseSampler(SamplerMixin):
instead.
"""

def __init__(self, sampling_strategy='auto', ratio=None):
def __init__(self, sampling_strategy="auto"):
self.sampling_strategy = sampling_strategy
# FIXME: remove in 0.6
self.ratio = ratio

@staticmethod
def _check_X_y(X, y):
y, binarize_y = check_target_type(y, indicate_one_vs_all=True)
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc'])
X, y = check_X_y(X, y, accept_sparse=["csr", "csc"])
return X, y, binarize_y

@property
def ratio_(self):
# FIXME: remove in 0.6
warnings.warn("'ratio' and 'ratio_' are deprecated. Use "
"'sampling_strategy' and 'sampling_strategy_' instead.",
DeprecationWarning)
return self.sampling_strategy_

def _deprecate_ratio(self):
# both ratio and sampling_strategy should not be set
if self.ratio is not None:
deprecate_parameter(self, '0.4', 'ratio', 'sampling_strategy')
self.sampling_strategy = self.ratio


def _identity(X, y):
return X, y
Expand Down Expand Up @@ -219,7 +200,7 @@ class FunctionSampler(BaseSampler):

"""

_sampling_type = 'bypass'
_sampling_type = "bypass"

def __init__(self, func=None, accept_sparse=True, kw_args=None):
super().__init__()
Expand All @@ -228,8 +209,9 @@ def __init__(self, func=None, accept_sparse=True, kw_args=None):
self.kw_args = kw_args

def _fit_resample(self, X, y):
X, y = check_X_y(X, y, accept_sparse=['csr', 'csc']
if self.accept_sparse else False)
X, y = check_X_y(
X, y, accept_sparse=["csr", "csc"] if self.accept_sparse else False
)
func = _identity if self.func is None else self.func
output = func(X, y, **(self.kw_args if self.kw_args else {}))
return output
2 changes: 1 addition & 1 deletion imblearn/combine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from ._smote_enn import SMOTEENN
from ._smote_tomek import SMOTETomek

__all__ = ['SMOTEENN', 'SMOTETomek']
__all__ = ["SMOTEENN", "SMOTETomek"]
Loading
0