MetaEstimatorMixin
- class sklearn.base.MetaEstimatorMixin
Mixin class for all meta estimators in scikit-learn.
This mixin is empty, and only exists to indicate that the estimator is a meta-estimator.
Examples
Mixin class for all meta estimators in scikit-learn.
This mixin is empty, and only exists to indicate that the estimator is a meta-estimator.
>>> 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()
Developing Estimators Compliant with Metadata Routing