为什么我们要使用python中的sklearn.base中的speastimator和transformermixmin来创建/自定义类?
我是从Python学习Sklearn的初学者。我知道我们可以独自创建任何类似的班级:
class name():
def __init__(self):
pass
def fit(self, x):
return something
我们需要使用sexestimator和transformermixmin如下:
from sklearn.base import BaseEstimator, Transformermixmin
class name(BaseEstimator, Transformermixmin):
def __init(self):
pass
def fit(self, x):
return self
但是我不明白为什么当我们尝试自定义变压器或Sklearn中的班级时, 另一个带有亚键式剂,transformermixmin? Laysestimator和Transformermixmin如何工作?它使用什么?有人可以回答上述问题,并给我更多的例子或清楚的解释吗?太感谢了!
I am a beginner at learning sklearn from Python. I know we could create any class by ourselves with something like that:
class name():
def __init__(self):
pass
def fit(self, x):
return something
But I cannot understand why when we try to custom the transformer or the class in sklearn we need to use BaseEstimator and Transformermixmin as below:
from sklearn.base import BaseEstimator, Transformermixmin
class name(BaseEstimator, Transformermixmin):
def __init(self):
pass
def fit(self, x):
return self
what is the difference between the empty class and the other one with BaseEstimator, Transformermixmin? How can BaseEstimator and Transformermixmin work and what does it used for? Can someone answer the above questions and give me more examples or clear explanations about them? Thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要从任何一类继承,但它们都可以帮助您。
superestimator
实现get_params
和set_params
for for for for for for for hou /developers/develop.html#instantiation“ rel =“ nofollow noreferrer”>__ init __ init __
方法的要求。这两种方法允许您的自定义变压器为clone
d,并使用GridSearchCV
或RandomizedSearchcv
进行了超参数调整。它还提供了一种打印方法来打印估算器的文本或HTML表示。它还包含一些常见的输入验证方法,以及最近的功能名称处理。transformermixin
实现fit_transform
作为fit
,然后是transform
。这很方便,尽管不超过superestimator
。另请参见“ Noreferrer”> Sklearn开发人员指南。
You do not need to inherit from either class, but they can both be helpful.
BaseEstimator
implementsget_params
andset_params
for you, assuming you adhere to the requirements for the__init__
method. These two methods allow your custom transformer to beclone
d and hyperparameter-tuned usingGridSearchCV
orRandomizedSearchCV
. It also provides a printing methods to print either text or html representation of your estimator. It also contains some common input validation methods, and more recently, feature name handling.TransformerMixin
implementsfit_transform
asfit
followed bytransform
. It's convenient, although not nearly so much asBaseEstimator
.See also the box titled "BaseEstimator and mixins" in the sklearn developer guide.