Spec-Zone.ru › scikit-learn

get_routing_for_object

sklearn.utils.metadata_routing.get_routing_for_object(obj=None)[source]

Get a Metadata{Router, Request} instance from the given object.

This function returns a MetadataRouter or a MetadataRequest from the given input.

This function always returns a copy or a new instance constructed from the input, such that changing the output of this function will not change the original object.

Added in version 1.3.

Parameters:
objobject
  • If the object provides a get_metadata_routing method, return a copy

    of the output of that method.

  • If the object is already a

    MetadataRequest or a MetadataRouter, return a copy of that.

  • Returns an empty MetadataRequest

    otherwise.

Returns:
objMetadataRequest or MetadataRouter

A MetadataRequest or a MetadataRouter taken or created from the given object.

Examples

>>> from sklearn.datasets import make_classification
>>> from sklearn.pipeline import Pipeline
>>> from sklearn.preprocessing import StandardScaler
>>> from sklearn.linear_model import LogisticRegressionCV
>>> from sklearn.utils.metadata_routing import get_routing_for_object
>>> X, y = make_classification()
>>> pipe = Pipeline(
...       [("scaler", StandardScaler()), ("lr_cv", LogisticRegressionCV())]
... )
>>> pipe.fit(X, y)
Pipeline(steps=[('scaler', StandardScaler()), ('lr_cv', LogisticRegressionCV())])
>>> type(get_routing_for_object(pipe))
<class 'sklearn.utils._metadata_requests.MetadataRouter'>
>>> type(get_routing_for_object(pipe.named_steps.scaler))
<class 'sklearn.utils._metadata_requests.MetadataRequest'>
>>> type(get_routing_for_object(pipe.named_steps.lr_cv))
<class 'sklearn.utils._metadata_requests.MetadataRouter'>

© 2007–2026 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.9/modules/generated/sklearn.utils.metadata_routing.get_routing_for_object.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API