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 MetadataRouting

From Leeroopedia


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

Overview

Concrete tool for routing metadata (such as sample weights) within scikit-learn estimator pipelines, provided by scikit-learn.

Description

The sklearn.utils.metadata_routing module provides utilities to route metadata within scikit-learn estimators. It re-exports key classes and functions from the internal _metadata_requests module, including MetadataRouter, MetadataRequest, MethodMapping, process_routing, and get_routing_for_object. It also provides sentinel values UNCHANGED, UNUSED, and WARN for controlling metadata request behavior.

Usage

Use this module when building custom estimators that need to pass metadata (like sample_weight or groups) through pipelines and composite estimators. It enables fine-grained control over which metadata is forwarded to which sub-estimator method.

Code Reference

Source Location

Signature

from sklearn.utils._metadata_requests import (
    UNCHANGED,
    UNUSED,
    WARN,
    MetadataRequest,
    MetadataRouter,
    MethodMapping,
    _MetadataRequester,
    _raise_for_params,
    _raise_for_unsupported_routing,
    _routing_enabled,
    _RoutingNotSupportedMixin,
    get_routing_for_object,
    process_routing,
)

Import

from sklearn.utils.metadata_routing import MetadataRouter, process_routing

I/O Contract

Inputs

Name Type Required Description
obj estimator Yes The estimator or meta-estimator to get routing information for
params dict Yes Metadata parameters to be routed to sub-estimators

Outputs

Name Type Description
routing MetadataRouter Router object containing routing configuration for the estimator
routed_params dict Metadata parameters routed to the appropriate sub-estimator methods

Usage Examples

Basic Usage

from sklearn.utils.metadata_routing import MetadataRouter, MethodMapping

router = MetadataRouter(owner="MyEstimator")
# Configure routing for sub-estimators in composite estimators
# This is primarily used internally by scikit-learn's meta-estimators

Related Pages

Page Connections

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