Skip to content

[MRG] Refactor ratio to pick up any class #290

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 53 commits into from
Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4f87df5
EHN enable multiclass ratio handling
glemaitre May 8, 2017
4e528ec
FIX simplify call to dictionary
glemaitre May 8, 2017
4996bbb
FIX RUS done
glemaitre May 8, 2017
3f5dffa
FIX Refactor ADASYN
glemaitre May 9, 2017
87a630d
FIX partial
glemaitre May 9, 2017
9825317
FIX refactor SMOTE
glemaitre May 11, 2017
b7021fc
FIX refactor SMOTE
glemaitre May 11, 2017
8a010fb
DOC add proper docstring
glemaitre May 11, 2017
f573af3
PEP8
glemaitre May 11, 2017
a85dcff
FIX ClusterCentroids
glemaitre May 11, 2017
cabf202
FIX refactor IHT
glemaitre May 11, 2017
d2539b1
FIX Nearmiss refactoring
glemaitre May 12, 2017
0ee50c1
FIX tomek links refactor
glemaitre May 12, 2017
118af0e
FIX refactor OSS
glemaitre May 12, 2017
96b102e
FIX NCR refactoring
glemaitre May 13, 2017
8ecfd88
FIX refactor combined methods with Pipeline
glemaitre May 13, 2017
d4b9c3e
FIX combine method targetting all classes when cleaning
glemaitre May 13, 2017
f5303ca
FIX balance cascade refactoring
glemaitre May 13, 2017
0e93429
EHN add the possibility to add a dict for ratio
glemaitre May 14, 2017
38fe8ca
TST add test for check_ratio
glemaitre May 14, 2017
7f076cf
TST add test for float
glemaitre May 14, 2017
d89c12d
FIX/TST adapt common test
glemaitre May 14, 2017
039420b
TST fix IHT tests
glemaitre May 14, 2017
a31c0e1
TST fix NCR
glemaitre May 14, 2017
02be5f5
FIX combine test
glemaitre May 14, 2017
6fba010
TST fix balance
glemaitre May 14, 2017
f2d541a
FIX doctest
glemaitre May 14, 2017
c4d74e2
FIX doctest
glemaitre May 14, 2017
a1ba5f7
FIX solve the pickle issue
glemaitre May 14, 2017
012d3db
FIX remove comments
glemaitre May 14, 2017
d7fb9ae
TST add test for NCR
glemaitre May 14, 2017
b691064
TST add knn balance cascade
glemaitre May 14, 2017
ecf241f
EHN add callable option for the ratio
glemaitre May 14, 2017
a048c54
DOC make doc cleaner
glemaitre May 14, 2017
acc98e8
FIX/DOC remove useless comments and clean doc
glemaitre May 14, 2017
18bc464
DEP deprecation of ratio as float
glemaitre May 14, 2017
b9d0e5a
EHN add base class for cleaning methods
glemaitre May 15, 2017
3f3fb16
TST add common test for multi class
glemaitre May 16, 2017
9bcec08
MAINT downgrade sphinx for the moment
glemaitre May 16, 2017
38e1806
TST/EHN add test for the ratio and specific ratio for cleaning sampling
glemaitre May 16, 2017
5aa541b
EHN remove redundant code
glemaitre May 18, 2017
7a45207
FIX warning
glemaitre May 18, 2017
15c158c
Remove useless base class
glemaitre May 19, 2017
834de2f
MAINT add christos back to some file
glemaitre May 19, 2017
db22871
EHN rename test and add a comment
glemaitre May 19, 2017
38708e6
DOC add hash_X_y in the API
glemaitre May 19, 2017
8e59009
[MRG] Incorporate chkoar remarks (#6)
massich May 22, 2017
18f726c
[MRG] Remove the init in base class (#7)
massich May 22, 2017
19f423a
EHN doc
glemaitre May 26, 2017
9f3cfbd
Merge branch 'is/121' of github.com:glemaitre/imbalanced-learn into i…
glemaitre May 26, 2017
e4892ac
FIX add extension for sphinx
glemaitre May 26, 2017
7aef770
EHN make deprecatin great again
glemaitre May 30, 2017
c5ab8b9
EHN Improve SMOTE and ADASYN
glemaitre May 30, 2017
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 circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- sudo apt-get install build-essential python-dev python-setuptools
# install numpy first as it is a compile time dependency for other packages
- pip install --upgrade numpy
- pip install --upgrade scipy matplotlib setuptools nose coverage sphinx pillow sphinx-gallery sphinx_rtd_theme
- pip install --upgrade scipy matplotlib setuptools nose coverage pillow sphinx-gallery sphinx_rtd_theme sphinx==1.5.6
# Installing required packages for `make -C doc check command` to work.
- sudo -E apt-get -yq update
- sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install dvipng texlive-latex-base texlive-latex-extra
Expand Down
17 changes: 16 additions & 1 deletion doc/_static/css/imbalanced-learn.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@

.highlight a {
text-decoration: underline;
}
}

.deprecated p {
padding: 10px 7px 10px 10px;
color: #b94a48;
background-color: #F3E5E5;
border: 1px solid #eed3d7;
}

.deprecated p span.versionmodified {
font-weight: bold;
}

.wy-nav-content {
max-width: 1200px !important;
}
7 changes: 5 additions & 2 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Combination of over- and under-sampling methods
===============================================

.. automodule:: imblearn.combine
:no-members:
:no-inherited-members:
:no-members:
:no-inherited-members:

.. currentmodule:: imblearn

Expand Down Expand Up @@ -174,3 +174,6 @@ Utilities
:toctree: generated/

utils.estimator_checks.check_estimator
utils.check_neighbors_object
utils.check_ratio
utils.hash_X_y
27 changes: 25 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
pass
# -- General configuration ------------------------------------------------


# If extensions (or modules to document with autodoc) are in another
# directory, add these directories to sys.path here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
sys.path.insert(0, os.path.abspath('sphinxext'))

from github_link import make_linkcode_resolve

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

Expand All @@ -39,9 +48,10 @@
# ones.
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
'sphinx.ext.todo', 'numpydoc', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig',
'sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.ifconfig',
'sphinx.ext.viewcode', 'sphinx_gallery.gen_gallery',
'sphinx.ext.autosummary'
'sphinx.ext.autosummary', 'numpydoc',
'sphinx_issues', 'sphinx.ext.linkcode'
]

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


# Config for sphinx_issues

issues_uri = 'https://github.com/scikit-learn-contrib/imbalanced-learn/issues/{issue}'
issues_github_path = 'scikit-learn-contrib/imbalanced-learn'
issues_user_uri = 'https://github.com/{user}'


def setup(app):
app.connect('autodoc-process-docstring', generate_example_rst)

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

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}

# 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/'
'imbalanced-learn/blob/{revision}/'
'{package}/{path}#L{lineno}')
97 changes: 97 additions & 0 deletions doc/sphinxext/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-------------------------------------------------------------------------------
The files
- numpydoc.py
- autosummary.py
- autosummary_generate.py
- docscrape.py
- docscrape_sphinx.py
- phantom_import.py
have the following license:

Copyright (C) 2008 Stefan van der Walt <stefan@mentat.za.net>, Pauli Virtanen <pav@iki.fi>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

-------------------------------------------------------------------------------
The files
- compiler_unparse.py
- comment_eater.py
- traitsdoc.py
have the following license:

This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative.

Copyright (c) 2006, Enthought, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Enthought, Inc. nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


-------------------------------------------------------------------------------
The files
- only_directives.py
- plot_directive.py
originate from Matplotlib (http://matplotlib.sf.net/) which has
the following license:

Copyright (c) 2002-2008 John D. Hunter; All Rights Reserved.

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.

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.

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.

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.

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.

6. This License Agreement will automatically terminate upon a material breach of its terms and conditions.

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.

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.

2 changes: 2 additions & 0 deletions doc/sphinxext/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include tests *.py
include *.txt
52 changes: 52 additions & 0 deletions doc/sphinxext/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=====================================
numpydoc -- Numpy's Sphinx extensions
=====================================

Numpy's documentation uses several custom extensions to Sphinx. These
are shipped in this ``numpydoc`` package, in case you want to make use
of them in third-party projects.

The following extensions are available:

- ``numpydoc``: support for the Numpy docstring format in Sphinx, and add
the code description directives ``np-function``, ``np-cfunction``, etc.
that support the Numpy docstring syntax.

- ``numpydoc.traitsdoc``: For gathering documentation about Traits attributes.

- ``numpydoc.plot_directives``: Adaptation of Matplotlib's ``plot::``
directive. Note that this implementation may still undergo severe
changes or eventually be deprecated.

- ``numpydoc.only_directives``: (DEPRECATED)

- ``numpydoc.autosummary``: (DEPRECATED) An ``autosummary::`` directive.
Available in Sphinx 0.6.2 and (to-be) 1.0 as ``sphinx.ext.autosummary``,
and it the Sphinx 1.0 version is recommended over that included in
Numpydoc.


numpydoc
========

Numpydoc inserts a hook into Sphinx's autodoc that converts docstrings
following the Numpy/Scipy format to a form palatable to Sphinx.

Options
-------

The following options can be set in conf.py:

- numpydoc_use_plots: bool

Whether to produce ``plot::`` directives for Examples sections that
contain ``import matplotlib``.

- numpydoc_show_class_members: bool

Whether to show all members of a class in the Methods and Attributes
sections automatically.

- numpydoc_edit_link: bool (DEPRECATED -- edit your HTML template instead)

Whether to insert an edit link after docstrings.
84 changes: 84 additions & 0 deletions doc/sphinxext/github_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from operator import attrgetter
import inspect
import subprocess
import os
import sys
from functools import partial

REVISION_CMD = 'git rev-parse --short HEAD'


def _get_git_revision():
try:
revision = subprocess.check_output(REVISION_CMD.split()).strip()
except (subprocess.CalledProcessError, OSError):
print('Failed to execute git to get revision')
return None
return revision.decode('utf-8')


def _linkcode_resolve(domain, info, package, url_fmt, revision):
"""Determine a link to online source for a class/method/function

This is called by sphinx.ext.linkcode

An example with a long-untouched module that everyone has
>>> _linkcode_resolve('py', {'module': 'tty',
... 'fullname': 'setraw'},
... package='tty',
... url_fmt='http://hg.python.org/cpython/file/'
... '{revision}/Lib/{package}/{path}#L{lineno}',
... revision='xxxx')
'http://hg.python.org/cpython/file/xxxx/Lib/tty/tty.py#L18'
"""

if revision is None:
return
if domain not in ('py', 'pyx'):
return
if not info.get('module') or not info.get('fullname'):
return

class_name = info['fullname'].split('.')[0]
if type(class_name) != str:
# Python 2 only
class_name = class_name.encode('utf-8')
module = __import__(info['module'], fromlist=[class_name])
obj = attrgetter(info['fullname'])(module)

try:
fn = inspect.getsourcefile(obj)
except Exception:
fn = None
if not fn:
try:
fn = inspect.getsourcefile(sys.modules[obj.__module__])
except Exception:
fn = None
if not fn:
return

fn = os.path.relpath(fn,
start=os.path.dirname(__import__(package).__file__))
try:
lineno = inspect.getsourcelines(obj)[1]
except Exception:
lineno = ''
return url_fmt.format(revision=revision, package=package,
path=fn, lineno=lineno)


def make_linkcode_resolve(package, url_fmt):
"""Returns a linkcode_resolve function for the given URL format

revision is a git commit reference (hash or name)

package is the name of the root module of the package

url_fmt is along the lines of ('https://github.com/USER/PROJECT/'
'blob/{revision}/{package}/'
'{path}#L{lineno}')
"""
revision = _get_git_revision()
return partial(_linkcode_resolve, revision=revision, package=package,
url_fmt=url_fmt)
Loading