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 MetaEstimatorUtils

From Leeroopedia
Revision as of 16:36, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Scikit_learn_Scikit_learn_MetaEstimatorUtils.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

Concrete tool for providing utilities and base classes for meta-estimators that compose named sub-estimators, provided by scikit-learn.

Description

The sklearn.utils.metaestimators module provides utilities for building meta-estimators. It includes _BaseComposition, an abstract base class for estimators composed of named sub-estimators (supporting the "estimator_name__parameter" syntax for nested parameter management), and the available_if decorator for conditionally exposing methods based on sub-estimator capabilities.

Usage

Use these utilities when building composite estimators like Pipeline, VotingClassifier, or StackingRegressor that manage collections of named sub-estimators and need to delegate method calls and parameter management.

Code Reference

Source Location

Signature

class _BaseComposition(BaseEstimator, metaclass=ABCMeta):
    @abstractmethod
    def __init__(self):
    def _get_params(self, attr, deep=True):
    def _set_params(self, attr, **params):

# Re-exported:
from sklearn.utils._available_if import available_if

Import

from sklearn.utils.metaestimators import available_if

I/O Contract

Inputs

Name Type Required Description
attr str Yes Name of the attribute containing list of (name, estimator) tuples
deep bool No If True, return params for sub-estimators (default True)
**params dict No Parameters to set on sub-estimators using name__param syntax

Outputs

Name Type Description
params dict Dictionary of parameters including nested sub-estimator parameters

Usage Examples

Basic Usage

from sklearn.utils.metaestimators import available_if

def _has_predict_proba(self):
    return hasattr(self.estimator, "predict_proba")

class MyMetaEstimator:
    @available_if(_has_predict_proba)
    def predict_proba(self, X):
        return self.estimator.predict_proba(X)

Related Pages

Page Connections

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