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

[MRG] MAINT drop python 2 and upgrade scikit-learn 0.21 #576

Merged
merged 13 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
MAINT drop python 2
  • Loading branch information
glemaitre committed Jun 7, 2019
commit 76f3174ea8d64948b8661453e23b179c9e9a5a15
10 changes: 5 additions & 5 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [('index', 'imbalanced-learn', u'imbalanced-learn Documentation',
[u'G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas'], 1)]
man_pages = [('index', 'imbalanced-learn', 'imbalanced-learn Documentation',
['G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas'], 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -290,8 +290,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'imbalanced-learn', u'imbalanced-learn Documentation',
u'G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas', 'imbalanced-learn',
('index', 'imbalanced-learn', 'imbalanced-learn Documentation',
'G. Lemaitre, F. Nogueira, D. Oliveira, C. Aridas', 'imbalanced-learn',
'Toolbox for imbalanced dataset in machine learning.', 'Miscellaneous'),
]

Expand Down Expand Up @@ -332,6 +332,6 @@ def setup(app):

# The following is used by sphinx.ext.linkcode to provide links to github
linkcode_resolve = make_linkcode_resolve('imblearn',
u'https://github.com/scikit-learn-contrib/'
'https://github.com/scikit-learn-contrib/'
'imbalanced-learn/blob/{revision}/'
'{package}/{path}#L{lineno}')
8 changes: 4 additions & 4 deletions doc/sphinxext/sphinx_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def user_role(name, rawtext, text, lineno,
if config.issues_user_uri:
ref = config.issues_user_uri.format(user=target)
else:
ref = 'https://github.com/{0}'.format(target)
ref = 'https://github.com/{}'.format(target)
if has_explicit_title:
text = title
else:
text = '@{0}'.format(target)
text = '@{}'.format(target)

link = nodes.reference(text=text, refuri=ref, **options)
return [link], []
Expand All @@ -66,10 +66,10 @@ def _make_issue_node(issue_no, config, options=None):
if config.issues_uri:
ref = config.issues_uri.format(issue=issue_no)
elif config.issues_github_path:
ref = 'https://github.com/{0}/issues/{1}'.format(
ref = 'https://github.com/{}/issues/{}'.format(
config.issues_github_path, issue_no
)
issue_text = '#{0}'.format(issue_no)
issue_text = '#{}'.format(issue_no)
link = nodes.reference(text=issue_text, refuri=ref, **options)
else:
link = None
Expand Down
2 changes: 1 addition & 1 deletion examples/applications/plot_over_sampling_benchmark_lfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
RANDOM_STATE = 42


class DummySampler(object):
class DummySampler:

def sample(self, X, y):
return X, y
Expand Down
2 changes: 1 addition & 1 deletion examples/model_selection/plot_validation_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
test_scores_mean - test_scores_std, alpha=0.2)
idx_max = np.argmax(test_scores_mean)
plt.scatter(param_range[idx_max], test_scores_mean[idx_max],
label=r'Cohen Kappa: ${0:.2f}\pm{1:.2f}$'.format(
label=r'Cohen Kappa: ${:.2f}\pm{:.2f}$'.format(
test_scores_mean[idx_max], test_scores_std[idx_max]))

plt.title("Validation Curve with SMOTE-CART")
Expand Down
6 changes: 3 additions & 3 deletions examples/under-sampling/plot_illustration_nearmiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def make_plot_despine(ax):
ax.plot([X_majority[positive_idx, 0], X_minority[sample_idx, 0]],
[X_majority[positive_idx, 1], X_minority[sample_idx, 1]],
'--' + color, alpha=0.3,
label='Avg. dist.={0:.2f}'.format(distance)
label='Avg. dist.={:.2f}'.format(distance)
if make_plot == 0 else "")
ax.set_title('NearMiss-1')
make_plot_despine(ax)
Expand Down Expand Up @@ -108,7 +108,7 @@ def make_plot_despine(ax):
ax.plot([X_majority[positive_idx, 0], X_minority[sample_idx, 0]],
[X_majority[positive_idx, 1], X_minority[sample_idx, 1]],
'--' + color, alpha=0.3,
label='Avg. dist.={0:.2f}'.format(distance)
label='Avg. dist.={:.2f}'.format(distance)
if make_plot == 0 else "")
ax.set_title('NearMiss-2')
make_plot_despine(ax)
Expand Down Expand Up @@ -148,7 +148,7 @@ def make_plot_despine(ax):
ax.plot([X_majority[positive_idx, 0], X_minority[sample_idx, 0]],
[X_majority[positive_idx, 1], X_minority[sample_idx, 1]],
'--' + color, alpha=0.3,
label='Avg. dist.={0:.2f}'.format(distance)
label='Avg. dist.={:.2f}'.format(distance)
if make_plot == 0 else "")
ax.set_title('NearMiss-3')
make_plot_despine(ax)
Expand Down
4 changes: 2 additions & 2 deletions imblearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .utils.deprecation import deprecate_parameter


class SamplerMixin(six.with_metaclass(ABCMeta, BaseEstimator)):
class SamplerMixin(BaseEstimator, metaclass=ABCMeta):
"""Mixin class for samplers with abstract method.

Warning: This class should not be used directly. Use the derive classes
Expand Down Expand Up @@ -225,7 +225,7 @@ class FunctionSampler(BaseSampler):
_sampling_type = 'bypass'

def __init__(self, func=None, accept_sparse=True, kw_args=None):
super(FunctionSampler, self).__init__()
super().__init__()
self.func = func
self.accept_sparse = accept_sparse
self.kw_args = kw_args
Expand Down
2 changes: 1 addition & 1 deletion imblearn/combine/_smote_enn.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self,
enn=None,
n_jobs=1,
ratio=None):
super(SMOTEENN, self).__init__()
super().__init__()
self.sampling_strategy = sampling_strategy
self.random_state = random_state
self.smote = smote
Expand Down
2 changes: 1 addition & 1 deletion imblearn/combine/_smote_tomek.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self,
tomek=None,
n_jobs=1,
ratio=None):
super(SMOTETomek, self).__init__()
super().__init__()
self.sampling_strategy = sampling_strategy
self.random_state = random_state
self.smote = smote
Expand Down
10 changes: 3 additions & 7 deletions imblearn/datasets/_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@
from collections import OrderedDict
import tarfile
from io import BytesIO
from os import makedirs
from os.path import join, isfile
try:
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
from urllib.request import urlopen

import numpy as np

from sklearn.datasets import get_data_home
from sklearn.datasets.base import Bunch
from sklearn.utils.fixes import makedirs
from sklearn.externals import six
from sklearn.utils import check_random_state

URL = ('https://zenodo.org/record/61452/files/'
Expand Down Expand Up @@ -211,7 +207,7 @@ def fetch_datasets(data_home=None,
list_data = MAP_NAME_ID.keys()
filter_data_ = []
for it in filter_data:
if isinstance(it, six.string_types):
if isinstance(it, str):
if it not in list_data:
raise ValueError('{} is not a dataset available. '
'The available datasets are {}'.format(
Expand Down
6 changes: 3 additions & 3 deletions imblearn/ensemble/_bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(self,
verbose=0,
ratio=None):

super(BalancedBaggingClassifier, self).__init__(
super().__init__(
base_estimator,
n_estimators=n_estimators,
max_samples=max_samples,
Expand All @@ -207,11 +207,11 @@ def _validate_estimator(self, default=DecisionTreeClassifier()):
`base_estimator_` attribute."""
if not isinstance(self.n_estimators, (numbers.Integral, np.integer)):
raise ValueError("n_estimators must be an integer, "
"got {0}.".format(type(self.n_estimators)))
"got {}.".format(type(self.n_estimators)))

if self.n_estimators <= 0:
raise ValueError("n_estimators must be greater than zero, "
"got {0}.".format(self.n_estimators))
"got {}.".format(self.n_estimators))

if self.base_estimator is not None:
base_estimator = clone(self.base_estimator)
Expand Down
2 changes: 1 addition & 1 deletion imblearn/ensemble/_balance_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self,
n_max_subset=None,
estimator=None,
ratio=None):
super(BalanceCascade, self).__init__(
super().__init__(
sampling_strategy=sampling_strategy, ratio=ratio)
self.random_state = random_state
self.return_indices = return_indices
Expand Down
8 changes: 4 additions & 4 deletions imblearn/ensemble/_easy_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self,
replacement=False,
n_subsets=10,
ratio=None):
super(EasyEnsemble, self).__init__(
super().__init__(
sampling_strategy=sampling_strategy, ratio=ratio)
self.random_state = random_state
self.return_indices = return_indices
Expand Down Expand Up @@ -235,7 +235,7 @@ class EasyEnsembleClassifier(BaggingClassifier):
def __init__(self, n_estimators=10, base_estimator=None, warm_start=False,
sampling_strategy='auto', replacement=False, n_jobs=1,
random_state=None, verbose=0):
super(EasyEnsembleClassifier, self).__init__(
super().__init__(
base_estimator,
n_estimators=n_estimators,
max_samples=1.0,
Expand All @@ -255,11 +255,11 @@ def _validate_estimator(self, default=AdaBoostClassifier()):
`base_estimator_` attribute."""
if not isinstance(self.n_estimators, (numbers.Integral, np.integer)):
raise ValueError("n_estimators must be an integer, "
"got {0}.".format(type(self.n_estimators)))
"got {}.".format(type(self.n_estimators)))

if self.n_estimators <= 0:
raise ValueError("n_estimators must be greater than zero, "
"got {0}.".format(self.n_estimators))
"got {}.".format(self.n_estimators))

if self.base_estimator is not None:
base_estimator = clone(self.base_estimator)
Expand Down
10 changes: 5 additions & 5 deletions imblearn/ensemble/_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def __init__(self,
verbose=0,
warm_start=False,
class_weight=None):
super(BalancedRandomForestClassifier, self).__init__(
super().__init__(
criterion=criterion,
max_depth=max_depth,
n_estimators=n_estimators,
Expand All @@ -288,11 +288,11 @@ def _validate_estimator(self, default=DecisionTreeClassifier()):
`base_estimator_` attribute."""
if not isinstance(self.n_estimators, (numbers.Integral, np.integer)):
raise ValueError("n_estimators must be an integer, "
"got {0}.".format(type(self.n_estimators)))
"got {}.".format(type(self.n_estimators)))

if self.n_estimators <= 0:
raise ValueError("n_estimators must be greater than zero, "
"got {0}.".format(self.n_estimators))
"got {}.".format(self.n_estimators))

if self.base_estimator is not None:
self.base_estimator_ = clone(self.base_estimator)
Expand All @@ -309,8 +309,8 @@ def _make_sampler_estimator(self, random_state=None):
sub-estimators.
"""
estimator = clone(self.base_estimator_)
estimator.set_params(**dict((p, getattr(self, p))
for p in self.estimator_params))
estimator.set_params(**{p: getattr(self, p)
for p in self.estimator_params})
sampler = clone(self.base_sampler_)

if random_state is not None:
Expand Down
12 changes: 6 additions & 6 deletions imblearn/ensemble/_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class RUSBoostClassifier(AdaBoostClassifier):
def __init__(self, base_estimator=None, n_estimators=50, learning_rate=1.,
algorithm='SAMME.R', sampling_strategy='auto',
replacement=False, random_state=None):
super(RUSBoostClassifier, self).__init__(
super().__init__(
base_estimator=base_estimator,
n_estimators=n_estimators,
learning_rate=learning_rate,
Expand Down Expand Up @@ -148,19 +148,19 @@ def fit(self, X, y, sample_weight=None):
"""
self.samplers_ = []
self.pipelines_ = []
super(RUSBoostClassifier, self).fit(X, y, sample_weight)
super().fit(X, y, sample_weight)
return self

def _validate_estimator(self, default=DecisionTreeClassifier()):
"""Check the estimator and the n_estimator attribute, set the
`base_estimator_` attribute."""
if not isinstance(self.n_estimators, (numbers.Integral, np.integer)):
raise ValueError("n_estimators must be an integer, "
"got {0}.".format(type(self.n_estimators)))
"got {}.".format(type(self.n_estimators)))

if self.n_estimators <= 0:
raise ValueError("n_estimators must be greater than zero, "
"got {0}.".format(self.n_estimators))
"got {}.".format(self.n_estimators))

if self.base_estimator is not None:
self.base_estimator_ = clone(self.base_estimator)
Expand All @@ -177,8 +177,8 @@ def _make_sampler_estimator(self, append=True, random_state=None):
sub-estimators.
"""
estimator = clone(self.base_estimator_)
estimator.set_params(**dict((p, getattr(self, p))
for p in self.estimator_params))
estimator.set_params(**{p: getattr(self, p)
for p in self.estimator_params})
sampler = clone(self.base_sampler_)

if random_state is not None:
Expand Down
4 changes: 2 additions & 2 deletions imblearn/ensemble/tests/test_bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def test_warm_start(random_state=42):
n_estimators=10, random_state=random_state, warm_start=False)
clf_no_ws.fit(X, y)

assert (set([pipe.steps[-1][1].random_state for pipe in clf_ws]) == set(
[pipe.steps[-1][1].random_state for pipe in clf_no_ws]))
assert ({pipe.steps[-1][1].random_state for pipe in clf_ws} == {
pipe.steps[-1][1].random_state for pipe in clf_no_ws})


def test_warm_start_smaller_n_estimators():
Expand Down
4 changes: 2 additions & 2 deletions imblearn/ensemble/tests/test_easy_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def test_warm_start(random_state=42):
n_estimators=10, random_state=random_state, warm_start=False)
clf_no_ws.fit(X, y)

assert (set([pipe.steps[-1][1].random_state for pipe in clf_ws]) == set(
[pipe.steps[-1][1].random_state for pipe in clf_no_ws]))
assert ({pipe.steps[-1][1].random_state for pipe in clf_ws} == {
pipe.steps[-1][1].random_state for pipe in clf_no_ws})


def test_warm_start_smaller_n_estimators():
Expand Down
4 changes: 2 additions & 2 deletions imblearn/ensemble/tests/test_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def test_rusboost(imbalanced_dataset, algorithm):
assert len(rusboost.pipelines_) == len(rusboost.samplers_)

# each sampler in the ensemble should have different random state
assert (len(set(sampler.random_state for sampler in rusboost.samplers_)) ==
assert (len({sampler.random_state for sampler in rusboost.samplers_}) ==
len(rusboost.samplers_))
# each estimator in the ensemble should have different random state
assert (len(set(est.random_state for est in rusboost.estimators_)) ==
assert (len({est.random_state for est in rusboost.estimators_}) ==
len(rusboost.estimators_))

# check the consistency of the feature importances
Expand Down
8 changes: 4 additions & 4 deletions imblearn/metrics/_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ def compute_score(*args, **kwargs):
# Make the intersection between the parameters
sel_params = params_sens_spec.intersection(set(tags_scoring_func))
# Create a sub dictionary
tags_scoring_func = dict((k, tags_scoring_func[k])
for k in sel_params)
tags_scoring_func = {k: tags_scoring_func[k]
for k in sel_params}
# Check if the metric is the geometric mean
if scoring_func.__name__ == 'geometric_mean_score':
if 'average' in tags_scoring_func:
Expand Down Expand Up @@ -883,7 +883,7 @@ class 2 1.00 0.67 1.00 0.80 0.82 0.64\
for v in (precision[i], recall[i], specificity[i], f1[i], geo_mean[i],
iba[i]):
values += ["{0:0.{1}f}".format(v, digits)]
values += ["{0}".format(support[i])]
values += ["{}".format(support[i])]
report += fmt % tuple(values)

report += '\n'
Expand All @@ -896,6 +896,6 @@ class 2 1.00 0.67 1.00 0.80 0.82 0.64\
geo_mean, weights=support), np.average(iba,
weights=support)):
values += ["{0:0.{1}f}".format(v, digits)]
values += ['{0}'.format(np.sum(support))]
values += ['{}'.format(np.sum(support))]
report += fmt % tuple(values)
return report
Loading