MetadataRequest
- classsklearn.utils.metadata_routing.MetadataRequest(owner)[source]
-
Container for storing metadata request info and an associated consumer (
owner).Instances of
MethodMetadataRequestare used in this class for each available method underMetadataRequest(owner=obj).{method}.Every consumer in scikit-learn has a
_metadata_requestattribute that is aMetadataRequest.Read more on developing custom estimators that can route metadata in the Metadata Routing Developing Guide.
Added in version 1.3.
- Parameters:
-
- ownerobject
-
The object to which these requests belong.
Examples
>>> from sklearn import set_config >>> set_config(enable_metadata_routing=True) >>> from pprint import pprint >>> from sklearn.utils.metadata_routing import MetadataRequest >>> r = MetadataRequest(owner="any_object") >>> r.fit.add_request(param="sample_weight", alias=True) {'sample_weight': True} >>> r.score.add_request(param="sample_weight", alias=False) {'sample_weight': False} >>> pprint(r) {'fit': {'sample_weight': True}, 'score': {'sample_weight': False}} >>> set_config(enable_metadata_routing=False)- consumes(method, params)[source]
-
Return params consumed as metadata in a consumer.
This method returns the subset of given
paramsthat are consumed by the givenmethod. It can be used to check if parameters are used as metadata in the specified method of the consumer that owns thisMetadataRequestinstance.Added in version 1.4.
- Parameters:
-
- methodstr
-
The name of the method for which to determine consumed parameters.
- paramsiterable of str
-
An iterable of parameter names to test for consumption.
- Returns:
-
- consumed_paramsset of str
-
A subset of parameters from
paramswhich are consumed by the given method.
© 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.MetadataRequest.html