MetaEstimatorMixin#
- class sklearn.base.MetaEstimatorMixin#
Mixin类用于scikit-learn中的所有元估计器。
这个mixin定义了以下功能:
定义
_required_parameters
,指定强制性的estimator
参数。
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#
元数据路由