Skip to content

Commit b246d06

Browse files
authored
[MRG] Refactor ratio to pick up any class (#290)
* EHN enable multiclass ratio handling * FIX simplify call to dictionary * FIX RUS done * FIX Refactor ADASYN * FIX partial * FIX refactor SMOTE * FIX refactor SMOTE * DOC add proper docstring * PEP8 * FIX ClusterCentroids * FIX refactor IHT * FIX Nearmiss refactoring * FIX tomek links refactor * FIX refactor OSS * FIX NCR refactoring * FIX refactor combined methods with Pipeline * FIX combine method targetting all classes when cleaning * FIX balance cascade refactoring * EHN add the possibility to add a dict for ratio * TST add test for check_ratio * TST add test for float * FIX/TST adapt common test * TST fix IHT tests * TST fix NCR * FIX combine test * TST fix balance * FIX doctest * FIX doctest * FIX solve the pickle issue * FIX remove comments * TST add test for NCR * TST add knn balance cascade * EHN add callable option for the ratio * DOC make doc cleaner * FIX/DOC remove useless comments and clean doc * DEP deprecation of ratio as float * EHN add base class for cleaning methods * TST add common test for multi class * MAINT downgrade sphinx for the moment * TST/EHN add test for the ratio and specific ratio for cleaning sampling * EHN remove redundant code * FIX warning * Remove useless base class * MAINT add christos back to some file * EHN rename test and add a comment * DOC add hash_X_y in the API * [MRG] Incorporate chkoar remarks (#6) * change cleaning-sampler to clean-sampler * Refactor the over_sampling * [WIP] adapt ensamble class * [MRG] Remove the init in base class (#7) * change cleaning-sampler to clean-sampler * Refactor the over_sampling * [WIP] adapt ensamble class * iterate * fix PEP8 * EHN doc * FIX add extension for sphinx * EHN make deprecatin great again * EHN Improve SMOTE and ADASYN
1 parent 8966358 commit b246d06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3359
-3457
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- sudo apt-get install build-essential python-dev python-setuptools
2424
# install numpy first as it is a compile time dependency for other packages
2525
- pip install --upgrade numpy
26-
- pip install --upgrade scipy matplotlib setuptools nose coverage sphinx pillow sphinx-gallery sphinx_rtd_theme
26+
- pip install --upgrade scipy matplotlib setuptools nose coverage pillow sphinx-gallery sphinx_rtd_theme sphinx==1.5.6
2727
# Installing required packages for `make -C doc check command` to work.
2828
- sudo -E apt-get -yq update
2929
- sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install dvipng texlive-latex-base texlive-latex-extra

doc/_static/css/imbalanced-learn.css

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@
22

33
.highlight a {
44
text-decoration: underline;
5-
}
5+
}
6+
7+
.deprecated p {
8+
padding: 10px 7px 10px 10px;
9+
color: #b94a48;
10+
background-color: #F3E5E5;
11+
border: 1px solid #eed3d7;
12+
}
13+
14+
.deprecated p span.versionmodified {
15+
font-weight: bold;
16+
}
17+
18+
.wy-nav-content {
19+
max-width: 1200px !important;
20+
}

doc/api.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Combination of over- and under-sampling methods
7777
===============================================
7878

7979
.. automodule:: imblearn.combine
80-
:no-members:
81-
:no-inherited-members:
80+
:no-members:
81+
:no-inherited-members:
8282

8383
.. currentmodule:: imblearn
8484

@@ -174,3 +174,6 @@ Utilities
174174
:toctree: generated/
175175

176176
utils.estimator_checks.check_estimator
177+
utils.check_neighbors_object
178+
utils.check_ratio
179+
utils.hash_X_y

doc/conf.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
pass
3232
# -- General configuration ------------------------------------------------
3333

34+
35+
# If extensions (or modules to document with autodoc) are in another
36+
# directory, add these directories to sys.path here. If the directory
37+
# is relative to the documentation root, use os.path.abspath to make it
38+
# absolute, like shown here.
39+
sys.path.insert(0, os.path.abspath('sphinxext'))
40+
41+
from github_link import make_linkcode_resolve
42+
3443
# If your documentation needs a minimal Sphinx version, state it here.
3544
# needs_sphinx = '1.0'
3645

@@ -39,9 +48,10 @@
3948
# ones.
4049
extensions = [
4150
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
42-
'sphinx.ext.todo', 'numpydoc', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig',
51+
'sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig',
4352
'sphinx.ext.viewcode', 'sphinx_gallery.gen_gallery',
44-
'sphinx.ext.autosummary'
53+
'sphinx.ext.autosummary', 'numpydoc',
54+
'sphinx_issues', 'sphinx.ext.linkcode'
4555
]
4656

4757
autosummary_generate = True
@@ -294,6 +304,13 @@ def generate_example_rst(app, what, name, obj, options, lines):
294304
open(examples_path, 'w').close()
295305

296306

307+
# Config for sphinx_issues
308+
309+
issues_uri = 'https://github.com/scikit-learn-contrib/imbalanced-learn/issues/{issue}'
310+
issues_github_path = 'scikit-learn-contrib/imbalanced-learn'
311+
issues_user_uri = 'https://github.com/{user}'
312+
313+
297314
def setup(app):
298315
app.connect('autodoc-process-docstring', generate_example_rst)
299316

@@ -312,3 +329,9 @@ def setup(app):
312329

313330
# Example configuration for intersphinx: refer to the Python standard library.
314331
intersphinx_mapping = {'http://docs.python.org/': None}
332+
333+
# The following is used by sphinx.ext.linkcode to provide links to github
334+
linkcode_resolve = make_linkcode_resolve('imblearn',
335+
u'https://github.com/scikit-learn-contrib/'
336+
'imbalanced-learn/blob/{revision}/'
337+
'{package}/{path}#L{lineno}')

doc/sphinxext/LICENSE.txt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
-------------------------------------------------------------------------------
2+
The files
3+
- numpydoc.py
4+
- autosummary.py
5+
- autosummary_generate.py
6+
- docscrape.py
7+
- docscrape_sphinx.py
8+
- phantom_import.py
9+
have the following license:
10+
11+
Copyright (C) 2008 Stefan van der Walt <stefan@mentat.za.net>, Pauli Virtanen <pav@iki.fi>
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are
15+
met:
16+
17+
1. Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
2. Redistributions in binary form must reproduce the above copyright
20+
notice, this list of conditions and the following disclaimer in
21+
the documentation and/or other materials provided with the
22+
distribution.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
28+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
POSSIBILITY OF SUCH DAMAGE.
35+
36+
-------------------------------------------------------------------------------
37+
The files
38+
- compiler_unparse.py
39+
- comment_eater.py
40+
- traitsdoc.py
41+
have the following license:
42+
43+
This software is OSI Certified Open Source Software.
44+
OSI Certified is a certification mark of the Open Source Initiative.
45+
46+
Copyright (c) 2006, Enthought, Inc.
47+
All rights reserved.
48+
49+
Redistribution and use in source and binary forms, with or without
50+
modification, are permitted provided that the following conditions are met:
51+
52+
* Redistributions of source code must retain the above copyright notice, this
53+
list of conditions and the following disclaimer.
54+
* Redistributions in binary form must reproduce the above copyright notice,
55+
this list of conditions and the following disclaimer in the documentation
56+
and/or other materials provided with the distribution.
57+
* Neither the name of Enthought, Inc. nor the names of its contributors may
58+
be used to endorse or promote products derived from this software without
59+
specific prior written permission.
60+
61+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
62+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
63+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
64+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
65+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
66+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
68+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
69+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
70+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71+
72+
73+
-------------------------------------------------------------------------------
74+
The files
75+
- only_directives.py
76+
- plot_directive.py
77+
originate from Matplotlib (http://matplotlib.sf.net/) which has
78+
the following license:
79+
80+
Copyright (c) 2002-2008 John D. Hunter; All Rights Reserved.
81+
82+
1. This LICENSE AGREEMENT is between John D. Hunter (“JDH”), and the Individual or Organization (“Licensee”) accessing and otherwise using matplotlib software in source or binary form and its associated documentation.
83+
84+
2. Subject to the terms and conditions of this License Agreement, JDH hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use matplotlib 0.98.3 alone or in any derivative version, provided, however, that JDH’s License Agreement and JDH’s notice of copyright, i.e., “Copyright (c) 2002-2008 John D. Hunter; All Rights Reserved” are retained in matplotlib 0.98.3 alone or in any derivative version prepared by Licensee.
85+
86+
3. In the event Licensee prepares a derivative work that is based on or incorporates matplotlib 0.98.3 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to matplotlib 0.98.3.
87+
88+
4. JDH is making matplotlib 0.98.3 available to Licensee on an “AS IS” basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB 0.98.3 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
89+
90+
5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB 0.98.3 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING MATPLOTLIB 0.98.3, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
91+
92+
6. This License Agreement will automatically terminate upon a material breach of its terms and conditions.
93+
94+
7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between JDH and Licensee. This License Agreement does not grant permission to use JDH trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party.
95+
96+
8. By copying, installing or otherwise using matplotlib 0.98.3, Licensee agrees to be bound by the terms and conditions of this License Agreement.
97+

doc/sphinxext/MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include tests *.py
2+
include *.txt

doc/sphinxext/README.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=====================================
2+
numpydoc -- Numpy's Sphinx extensions
3+
=====================================
4+
5+
Numpy's documentation uses several custom extensions to Sphinx. These
6+
are shipped in this ``numpydoc`` package, in case you want to make use
7+
of them in third-party projects.
8+
9+
The following extensions are available:
10+
11+
- ``numpydoc``: support for the Numpy docstring format in Sphinx, and add
12+
the code description directives ``np-function``, ``np-cfunction``, etc.
13+
that support the Numpy docstring syntax.
14+
15+
- ``numpydoc.traitsdoc``: For gathering documentation about Traits attributes.
16+
17+
- ``numpydoc.plot_directives``: Adaptation of Matplotlib's ``plot::``
18+
directive. Note that this implementation may still undergo severe
19+
changes or eventually be deprecated.
20+
21+
- ``numpydoc.only_directives``: (DEPRECATED)
22+
23+
- ``numpydoc.autosummary``: (DEPRECATED) An ``autosummary::`` directive.
24+
Available in Sphinx 0.6.2 and (to-be) 1.0 as ``sphinx.ext.autosummary``,
25+
and it the Sphinx 1.0 version is recommended over that included in
26+
Numpydoc.
27+
28+
29+
numpydoc
30+
========
31+
32+
Numpydoc inserts a hook into Sphinx's autodoc that converts docstrings
33+
following the Numpy/Scipy format to a form palatable to Sphinx.
34+
35+
Options
36+
-------
37+
38+
The following options can be set in conf.py:
39+
40+
- numpydoc_use_plots: bool
41+
42+
Whether to produce ``plot::`` directives for Examples sections that
43+
contain ``import matplotlib``.
44+
45+
- numpydoc_show_class_members: bool
46+
47+
Whether to show all members of a class in the Methods and Attributes
48+
sections automatically.
49+
50+
- numpydoc_edit_link: bool (DEPRECATED -- edit your HTML template instead)
51+
52+
Whether to insert an edit link after docstrings.

doc/sphinxext/github_link.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from operator import attrgetter
2+
import inspect
3+
import subprocess
4+
import os
5+
import sys
6+
from functools import partial
7+
8+
REVISION_CMD = 'git rev-parse --short HEAD'
9+
10+
11+
def _get_git_revision():
12+
try:
13+
revision = subprocess.check_output(REVISION_CMD.split()).strip()
14+
except (subprocess.CalledProcessError, OSError):
15+
print('Failed to execute git to get revision')
16+
return None
17+
return revision.decode('utf-8')
18+
19+
20+
def _linkcode_resolve(domain, info, package, url_fmt, revision):
21+
"""Determine a link to online source for a class/method/function
22+
23+
This is called by sphinx.ext.linkcode
24+
25+
An example with a long-untouched module that everyone has
26+
>>> _linkcode_resolve('py', {'module': 'tty',
27+
... 'fullname': 'setraw'},
28+
... package='tty',
29+
... url_fmt='http://hg.python.org/cpython/file/'
30+
... '{revision}/Lib/{package}/{path}#L{lineno}',
31+
... revision='xxxx')
32+
'http://hg.python.org/cpython/file/xxxx/Lib/tty/tty.py#L18'
33+
"""
34+
35+
if revision is None:
36+
return
37+
if domain not in ('py', 'pyx'):
38+
return
39+
if not info.get('module') or not info.get('fullname'):
40+
return
41+
42+
class_name = info['fullname'].split('.')[0]
43+
if type(class_name) != str:
44+
# Python 2 only
45+
class_name = class_name.encode('utf-8')
46+
module = __import__(info['module'], fromlist=[class_name])
47+
obj = attrgetter(info['fullname'])(module)
48+
49+
try:
50+
fn = inspect.getsourcefile(obj)
51+
except Exception:
52+
fn = None
53+
if not fn:
54+
try:
55+
fn = inspect.getsourcefile(sys.modules[obj.__module__])
56+
except Exception:
57+
fn = None
58+
if not fn:
59+
return
60+
61+
fn = os.path.relpath(fn,
62+
start=os.path.dirname(__import__(package).__file__))
63+
try:
64+
lineno = inspect.getsourcelines(obj)[1]
65+
except Exception:
66+
lineno = ''
67+
return url_fmt.format(revision=revision, package=package,
68+
path=fn, lineno=lineno)
69+
70+
71+
def make_linkcode_resolve(package, url_fmt):
72+
"""Returns a linkcode_resolve function for the given URL format
73+
74+
revision is a git commit reference (hash or name)
75+
76+
package is the name of the root module of the package
77+
78+
url_fmt is along the lines of ('https://github.com/USER/PROJECT/'
79+
'blob/{revision}/{package}/'
80+
'{path}#L{lineno}')
81+
"""
82+
revision = _get_git_revision()
83+
return partial(_linkcode_resolve, revision=revision, package=package,
84+
url_fmt=url_fmt)

0 commit comments

Comments
 (0)