parametrize_with_checks#

imblearn.utils.estimator_checks.parametrize_with_checks(estimators, *, legacy=True, expected_failed_checks=None)[source]#

用于参数化估计器检查的Pytest特定装饰器。

检查被分类为以下几组:

每个检查的id被设置为估计器的pprint版本和检查的名称及其关键字参数。 这允许使用pytest -k来指定要运行的测试:

pytest test_check_estimators.py -k check_estimators_fit_returns_self
Parameters:
estimatorslist of estimators instances

用于生成检查的估计器。

在版本0.24中更改:在版本0.23中已弃用传递类,并且在0.24中移除了对类的支持。请传递一个实例代替。

在版本0.24中添加。

legacybool, default=True

是否包含遗留检查。随着时间的推移,我们会从此类别中移除检查,并将它们移至其特定类别。

在版本1.6中添加。

expected_failed_checkscallable, default=None

一个可调用对象,它接受一个估计器作为输入并返回一个字典,形式如下:

{
    "check_name": "my reason",
}

其中 "check_name" 是检查的名称,而 "my reason" 是检查失败的原因。如果检查失败,这些测试将被标记为 xfail。

在版本1.6中添加。

Returns:
decoratorpytest.mark.parametrize

另请参阅

check_estimator

检查估计器是否遵循scikit-learn的约定。

示例

>>> from sklearn.utils.estimator_checks import parametrize_with_checks
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.tree import DecisionTreeRegressor
>>> @parametrize_with_checks([LogisticRegression(),
...                           DecisionTreeRegressor()])
... def test_sklearn_compatible_estimator(estimator, check):
...     check(estimator)