为什么我们要使用python中的sklearn.base中的speastimator和transformermixmin来创建/自定义类?

发布于 2025-02-10 02:38:13 字数 570 浏览 0 评论 0原文

我是从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2025-02-17 02:38:13

您不需要从任何一类继承,但它们都可以帮助您。

superestimator实现get_paramsset_params for for for for for for for hou /developers/develop.html#instantiation“ rel =“ nofollow noreferrer”> __ init __ init __方法的要求。这两种方法允许您的自定义变压器为clone d,并使用GridSearchCVRandomizedSearchcv进行了超参数调整。它还提供了一种打印方法来打印估算器的文本或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 implements get_params and set_params for you, assuming you adhere to the requirements for the __init__ method. These two methods allow your custom transformer to be cloned and hyperparameter-tuned using GridSearchCV or RandomizedSearchCV. 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 implements fit_transform as fit followed by transform. It's convenient, although not nearly so much as BaseEstimator.

See also the box titled "BaseEstimator and mixins" in the sklearn developer guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文