如何在XGBoost或其他估计器中编写定制包装器以用于预测功能

发布于 2025-01-28 14:21:32 字数 417 浏览 4 评论 0原文

因此,我想操纵我的预测结果,需要在估算器中进行。我试图写这样的包装器,但是当我执行预测功能时,我的内核只是死了。从我的理解中,这应该替换XGBoost中的预测功能,对吗?

from xgboost import XGBRegressor as xgb


class custXGB(xgb):

   def predict(self, X, y=None):
        return self.predict(X)

然后,我正常适合CLA,但是当我使用时,预测内核死亡而不会出错:

estimator = custXGB()
estimator.fit(X_train, y_train)
# works fine

estimator.predict(X_train)
#kernel dies

So I want to manipulate the result of my prediction and I need to do it within the estimator. I tried to write a wrapper like this, but my kernel just dies when I execute the predict function. From my understanding this should just replace the predict function in xgboost right?

from xgboost import XGBRegressor as xgb


class custXGB(xgb):

   def predict(self, X, y=None):
        return self.predict(X)

I then fit the clas normally but when I use predict the kernel dies without error:

estimator = custXGB()
estimator.fit(X_train, y_train)
# works fine

estimator.predict(X_train)
#kernel dies

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

清风挽心 2025-02-04 14:21:33

您已经写了一个无限循环:您的预测是调用本身,而不是xgbRegressor.predictselfsuper()在方法内替换。

You've written an infinite loop: your predict is calling itself, not the XGBRegressor.predict. Replace self with super() inside the method.

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