예제 #1
0
def test_all_estimators():
    # check if the filtering is working with a list or a single string
    type_filter = "sampler"
    all_estimators(type_filter=type_filter)
    type_filter = ["sampler"]
    estimators = all_estimators(type_filter=type_filter)
    for estimator in estimators:
        # check that all estimators are sampler
        assert issubclass(estimator[1], SamplerMixin)

    # check that an error is raised when the type is unknown
    type_filter = "rnd"
    with raises(ValueError, match="Parameter type_filter must be 'sampler'"):
        all_estimators(type_filter=type_filter)
예제 #2
0
def test_all_estimators():
    # check if the filtering is working with a list or a single string
    type_filter = 'sampler'
    all_estimators(type_filter=type_filter)
    type_filter = ['sampler']
    estimators = all_estimators(type_filter=type_filter)
    for estimator in estimators:
        # check that all estimators are sampler
        assert issubclass(estimator[1], SamplerMixin)

    # check that an error is raised when the type is unknown
    type_filter = 'rnd'
    with raises(ValueError, match="Parameter type_filter must be 'sampler'"):
        all_estimators(type_filter=type_filter)
예제 #3
0
def test_all_estimators():
    estimators = all_estimators(include_meta_estimators=True)
    assert len(estimators) > 0
    for name, Estimator in estimators:
        # some can just not be sensibly default constructed
        yield (_named_check(check_estimator, name),
               Estimator)
예제 #4
0
def test_all_estimators():
    # check if the filtering is working with a list or a single string
    type_filter = 'sampler'
    all_estimators(type_filter=type_filter)
    type_filter = ['sampler']
    estimators = all_estimators(type_filter=type_filter)
    for estimator in estimators:
        # check that all estimators are sampler
        assert issubclass(estimator[1], SamplerMixin)

    # check that an error is raised when the type is unknown
    type_filter = 'rnd'
    assert_raises_regex(ValueError,
                        "Parameter type_filter must be 'sampler'",
                        all_estimators,
                        type_filter=type_filter)
예제 #5
0
def test_non_meta_estimators():
    # input validation etc for non-meta estimators
    estimators = all_estimators()
    for name, Estimator in estimators:
        if name.startswith("_"):
            continue
        for check in _yield_all_checks(name, Estimator):
            yield _named_check(check, name), name, Estimator
예제 #6
0
def test_non_meta_estimators():
    # input validation etc for non-meta estimators
    estimators = all_estimators()
    for name, Estimator in estimators:
        if name.startswith("_"):
            continue
        for check in _yield_all_checks(name, Estimator):
            yield _named_check(check, name), name, Estimator

            logger_name = Estimator().logger.name
            class_module_name = Estimator.__module__
            assert logger_name == class_module_name
예제 #7
0
def test_non_meta_estimators():
    # input validation etc for non-meta estimators
    estimators = all_estimators()
    for name, Estimator in estimators:
        if name.startswith("_"):
            continue
        for check in _yield_all_checks(name, Estimator):
            yield _named_check(check, name), name, Estimator

            logger_name = Estimator().logger.name
            class_module_name = Estimator.__module__
            assert logger_name == class_module_name
예제 #8
0
def _tested_estimators():
    for name, Estimator in all_estimators():
        try:
            estimator = _construct_instance(Estimator)
            set_random_state(estimator)
        except SkipTest:
            continue

        if isinstance(estimator, NearMiss):
            # For NearMiss, let's check the three algorithms
            for version in (1, 2, 3):
                yield clone(estimator).set_params(version=version)
        else:
            yield estimator
예제 #9
0
def get_all_methods():
    estimators = all_estimators()
    for name, Estimator in estimators:
        if name.startswith("_"):
            # skip private classes
            continue
        methods = []
        for name in dir(Estimator):
            if name.startswith("_"):
                continue
            method_obj = getattr(Estimator, name)
            if hasattr(method_obj, "__call__") or isinstance(
                    method_obj, property):
                methods.append(name)
        methods.append(None)

        for method in sorted(methods, key=lambda x: str(x)):
            yield Estimator, method
예제 #10
0
def test_all_estimators():
    estimators = all_estimators(include_meta_estimators=True)
    assert_greater(len(estimators), 0)
    for name, Estimator in estimators:
        # some can just not be sensibly default constructed
        yield (_named_check(check_estimator, name), Estimator)
예제 #11
0
def test_all_estimator_no_base_class():
    # test that all_estimators doesn't find abstract classes.
    for name, Estimator in all_estimators():
        msg = ("Base estimators such as {0} should not be included"
               " in all_estimators").format(name)
        assert not name.lower().startswith('base'), msg
예제 #12
0
"""Common tests"""
# Authors: Guillaume Lemaitre <*****@*****.**>
#          Christos Aridas
# License: MIT

import pytest

from imblearn.utils.estimator_checks import check_estimator
from imblearn.utils.estimator_checks import _yield_all_checks
from imblearn.utils.testing import all_estimators


@pytest.mark.parametrize("name, Estimator", all_estimators())
def test_all_estimator_no_base_class(name, Estimator):
    # test that all_estimators doesn't find abstract classes.
    msg = (
        "Base estimators such as {0} should not be included"
        " in all_estimators"
    ).format(name)
    assert not name.lower().startswith("base"), msg


@pytest.mark.filterwarnings("ignore:'y' should be of types")
@pytest.mark.filterwarnings("ignore:The number of the samples to")
@pytest.mark.parametrize(
    "name, Estimator", all_estimators(include_meta_estimators=True)
)
def test_all_estimators(name, Estimator):
    # don't run twice the sampler tests. Meta-estimator do not have a
    # fit_resample method.
    check_estimator(Estimator, run_sampler_tests=False)
예제 #13
0
"""Common tests"""
# Authors: Guillaume Lemaitre <*****@*****.**>
#          Christos Aridas
# License: MIT

import pytest

from imblearn.utils.estimator_checks import check_estimator, _yield_all_checks
from imblearn.utils.testing import all_estimators


@pytest.mark.parametrize('name, Estimator', all_estimators())
def test_all_estimator_no_base_class(name, Estimator):
    # test that all_estimators doesn't find abstract classes.
    msg = ("Base estimators such as {0} should not be included"
           " in all_estimators").format(name)
    assert not name.lower().startswith('base'), msg


@pytest.mark.filterwarnings("ignore:'ratio' is deprecated from 0.4")
@pytest.mark.filterwarnings("ignore:'sampling_strategy' as a dict for")
@pytest.mark.filterwarnings("ignore:Class EasyEnsemble is deprecated")
@pytest.mark.filterwarnings('ignore:Class BalanceCascade is deprecated')
@pytest.mark.filterwarnings('ignore:"kind" is deprecated in 0.4 and will be')
@pytest.mark.filterwarnings('ignore:"svm_estimator" is deprecated in 0.4 and')
@pytest.mark.filterwarnings('ignore:"out_step" is deprecated in 0.4 and')
@pytest.mark.filterwarnings('ignore:"m_neighbors" is deprecated in 0.4 and')
@pytest.mark.filterwarnings("ignore:'y' should be of types")
@pytest.mark.filterwarnings("ignore:The number of the samples to")
@pytest.mark.parametrize('name, Estimator',
                         all_estimators(include_meta_estimators=True))
예제 #14
0
파일: test_common.py 프로젝트: yueyuep/TCNN
"""Common tests"""
# Authors: Guillaume Lemaitre <*****@*****.**>
#          Christos Aridas
# License: MIT

import pytest

from imblearn.utils.estimator_checks import check_estimator, _yield_all_checks
from imblearn.utils.testing import all_estimators


@pytest.mark.parametrize(
    'name, Estimator',
    all_estimators()
)
def test_all_estimator_no_base_class(name, Estimator):
    # test that all_estimators doesn't find abstract classes.
    msg = ("Base estimators such as {0} should not be included"
           " in all_estimators").format(name)
    assert not name.lower().startswith('base'), msg


@pytest.mark.filterwarnings("ignore:'ratio' is deprecated from 0.4")
@pytest.mark.filterwarnings("ignore:'sampling_strategy' as a dict for")
@pytest.mark.filterwarnings("ignore:Class EasyEnsemble is deprecated")
@pytest.mark.filterwarnings('ignore:"kind" is deprecated in 0.4 and will be')
@pytest.mark.filterwarnings('ignore:"svm_estimator" is deprecated in 0.4 and')
@pytest.mark.filterwarnings('ignore:"out_step" is deprecated in 0.4 and')
@pytest.mark.filterwarnings('ignore:"m_neighbors" is deprecated in 0.4 and')
@pytest.mark.filterwarnings("ignore:'y' should be of types")
@pytest.mark.parametrize(
예제 #15
0
def _tested_non_meta_estimators():
    for name, Estimator in all_estimators():
        if name.startswith("_"):
            continue
        yield name, Estimator
예제 #16
0
"""Common tests"""
# Authors: Guillaume Lemaitre <*****@*****.**>
#          Christos Aridas
# License: MIT

import pytest

from imblearn.utils.estimator_checks import check_estimator, _yield_all_checks
from imblearn.utils.testing import all_estimators


@pytest.mark.parametrize(
    'name, Estimator',
    all_estimators()
)
def test_all_estimator_no_base_class(name, Estimator):
    # test that all_estimators doesn't find abstract classes.
    msg = ("Base estimators such as {0} should not be included"
           " in all_estimators").format(name)
    assert not name.lower().startswith('base'), msg


@pytest.mark.filterwarnings("ignore:'ratio' is deprecated from 0.4")
@pytest.mark.filterwarnings("ignore:'sampling_strategy' as a dict for")
@pytest.mark.filterwarnings("ignore:Class EasyEnsemble is deprecated")
@pytest.mark.filterwarnings('ignore:Class BalanceCascade is deprecated')
@pytest.mark.filterwarnings('ignore:"kind" is deprecated in 0.4 and will be')
@pytest.mark.filterwarnings('ignore:"svm_estimator" is deprecated in 0.4 and')
@pytest.mark.filterwarnings('ignore:"out_step" is deprecated in 0.4 and')
@pytest.mark.filterwarnings('ignore:"m_neighbors" is deprecated in 0.4 and')
@pytest.mark.filterwarnings("ignore:'y' should be of types")
예제 #17
0
def test_all_estimator_no_base_class():
    # test that all_estimators doesn't find abstract classes.
    for name, Estimator in all_estimators():
        msg = ("Base estimators such as {0} should not be included"
               " in all_estimators").format(name)
        assert_false(name.lower().startswith('base'), msg=msg)
예제 #18
0
def _tested_non_meta_estimators():
    for name, Estimator in all_estimators():
        if name.startswith("_"):
            continue
        yield name, Estimator
예제 #19
0
from sklearn.exceptions import ConvergenceWarning
from sklearn.utils.estimator_checks import parametrize_with_checks as \
    parametrize_with_checks_sklearn
from sklearn.utils.estimator_checks import _construct_instance
from sklearn.utils._testing import ignore_warnings
from sklearn.utils._testing import set_random_state
from sklearn.utils._testing import SkipTest

from imblearn.utils.estimator_checks import parametrize_with_checks
from imblearn.utils.estimator_checks import _set_checking_parameters
from imblearn.utils.estimator_checks import _yield_all_checks
from imblearn.utils.testing import all_estimators
from imblearn.under_sampling import NearMiss


@pytest.mark.parametrize("name, Estimator", all_estimators())
def test_all_estimator_no_base_class(name, Estimator):
    # test that all_estimators doesn't find abstract classes.
    msg = (f"Base estimators such as {name} should not be included"
           f" in all_estimators")
    assert not name.lower().startswith("base"), msg


def _tested_estimators():
    for name, Estimator in all_estimators():
        try:
            estimator = _construct_instance(Estimator)
            set_random_state(estimator)
        except SkipTest:
            continue
예제 #20
0
    def valid_components(self):
        if not hasattr(self, "valid_components_"):
            self.valid_components_ = np.array(all_estimators())

        return self.valid_components_