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)
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)
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)
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)
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
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
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
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
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)
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
"""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)
"""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))
"""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(
def _tested_non_meta_estimators(): for name, Estimator in all_estimators(): if name.startswith("_"): continue yield name, Estimator
"""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")
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)
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
def valid_components(self): if not hasattr(self, "valid_components_"): self.valid_components_ = np.array(all_estimators()) return self.valid_components_