MetaEstimatorMixin#

class sklearn.base.MetaEstimatorMixin[來源]#

scikit-learn 中所有元估算器的混合類。

此混合類為空,僅用於指示估算器是元估算器。

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