MetaEstimatorMixin#
- class sklearn.base.MetaEstimatorMixin[source]#
Mixin class for all meta estimators in scikit-learn.
This mixin defines the following functionality:
define
_required_parameters
that specify the mandatoryestimator
parameter.
Examples
>>> from sklearn.base import MetaEstimatorMixin >>> from sklearn.datasets import load_iris >>> from sklearn.linear_model import LogisticRegression >>> class MyEstimator(MetaEstimatorMixin): ... def __init__(self, *, estimator=None): ... self.estimator = estimator ... def fit(self, X, y=None): ... if self.estimator is None: ... self.estimator_ = LogisticRegression() ... else: ... self.estimator_ = self.estimator ... return self >>> X, y = load_iris(return_X_y=True) >>> estimator = MyEstimator().fit(X, y) >>> estimator.estimator_ LogisticRegression()
Gallery examples#
Metadata Routing