Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn MockingUtils

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Testing
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete utility module for mock estimators used in testing provided by scikit-learn.

Description

The _mocking module provides mock data structures and estimators for testing scikit-learn pipelines and meta-estimators. It includes MockDataFrame for simulating pandas DataFrames, ArraySlicingWrapper for iloc-like indexing, and CheckingClassifier which is a dummy classifier that validates properties of X and y during fit/predict operations.

Usage

Use these utilities when writing tests for scikit-learn pipelines, cross-validation, or meta-estimators to verify that data is passed correctly and that fit_params are propagated as expected.

Code Reference

Source Location

Signature

class ArraySlicingWrapper:
    def __init__(self, array):
        ...

class MockDataFrame:
    def __init__(self, array):
        ...

class CheckingClassifier(ClassifierMixin, BaseEstimator):
    def __init__(self, check_y=None, check_X=None, ...):
        ...

Import

from sklearn.utils._mocking import CheckingClassifier, MockDataFrame

I/O Contract

Inputs

Name Type Required Description
check_y callable No Callable to validate y in fit/predict
check_X callable No Callable to validate X in fit/predict
array ndarray Yes Array to wrap (for MockDataFrame)

Outputs

Name Type Description
predictions ndarray Predictions from CheckingClassifier (configurable score)
MockDataFrame object DataFrame-like wrapper around a numpy array

Usage Examples

Basic Usage

import numpy as np
from sklearn.utils._mocking import CheckingClassifier

X = np.array([[1, 2], [3, 4], [5, 6]])
y = np.array([0, 1, 0])

clf = CheckingClassifier()
clf.fit(X, y)
predictions = clf.predict(X)
print(predictions)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment