元估计器Mixin #

class sklearn.base.MetaEstimatorMixin[source]#

scikit-learn中所有元估计器的Mixin类。

此Mixin为空,仅用于指示估计器是元估计器。

1.6版本中的更改: _required_parameters现已删除,因为测试已重构,不再使用它。

示例

>>> 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()