Implementation:Scikit learn Scikit learn EstimatorChecks
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, API Compliance Testing |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete utility module for verifying estimator compatibility with the scikit-learn API provided by scikit-learn.
Description
The estimator_checks module provides a comprehensive suite of checks to verify that custom estimators conform to the scikit-learn API contract. It tests cloning, pickling, parameter validation, fit/predict behavior, sparse input handling, multioutput support, and many more aspects. The main entry points are check_estimator and parametrize_with_checks for use with pytest.
Usage
Use check_estimator or parametrize_with_checks when developing custom scikit-learn estimators to ensure they comply with the scikit-learn API. This is the standard way to validate third-party estimators.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/utils/estimator_checks.py
Signature
def check_estimator(estimator=None, generate_only=False, *, on_skip="warn", on_fail="raise",
callback=None, expected_failed_checks=None, array_api_dispatch=False):
...
def parametrize_with_checks(estimators, *, expected_failed_checks=None):
...
# Individual check functions (examples):
# check_estimators_dtypes, check_fit_score_takes_y, check_estimators_overwrite_params,
# check_classifiers_train, check_regressors_train, check_pipeline_consistency, etc.
Import
from sklearn.utils.estimator_checks import check_estimator, parametrize_with_checks
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| estimator | estimator instance | Yes | The estimator to validate against the scikit-learn API |
| generate_only | bool | No | If True, return a generator of (estimator, check) tuples |
| on_skip | str | No | Action when a check is skipped: "warn" or "pass" |
| on_fail | str | No | Action on failure: "raise" or "warn" |
| expected_failed_checks | dict | No | Dictionary of expected failures for known issues |
Outputs
| Name | Type | Description |
|---|---|---|
| None | None | Raises errors or warnings if checks fail |
| generator | generator | If generate_only=True, yields (estimator, check) tuples |
Usage Examples
Basic Usage
from sklearn.utils.estimator_checks import check_estimator
from sklearn.linear_model import LogisticRegression
# Run all API compliance checks
check_estimator(LogisticRegression())
# Use with pytest parametrize
from sklearn.utils.estimator_checks import parametrize_with_checks
@parametrize_with_checks([LogisticRegression()])
def test_sklearn_compatible_estimator(estimator, check):
check(estimator)