XGBRegressor score 方法返回奇怪的值 [英] XGBRegressor score method returning strange values

查看:69
本文介绍了XGBRegressor score 方法返回奇怪的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Python API 中的 XGBRegressor 的 score 方法,它返回 0.917 的结果.我期望这是回归的 r2 分数.

I've tried to use XGBRegressor's score method from the Python API and It's returning a result of 0.917. I am expecting this to be the r2 score of the regression.

但是,在同一个包上尝试 sklearn 中的 r2_score,它返回不同的值 (0.903)

However, trying r2_score from sklearn on the same package, it returns a different value (0.903)

xgbr.score(x_test, y_test) # Returns 0.917
y_pred = xgbr.predict(x_test)
r2_score(y_pred, y_test) # Returns 0.903

这是怎么回事?我找不到任何关于 XGBoost 评分方法的文档.我正在使用 v0.7

What's going on? I couldn't find any documentation on XGBoost's score method. I'm using v0.7

推荐答案

当你调用 xgbr.score() 时,这段代码实际上是在调用:

When you call xgbr.score() this code is actually called:

    ...
    return r2_score(y, self.predict(X), sample_weight=None,
                    multioutput='variance_weighted')

但是当您显式调用 r2_score 时,multiouput 参数的默认值为uniform_average".

But when you are calling the r2_score explicitly, the default value of multiouput param is "uniform_average".

试试下面的代码:

r2_score(y_pred, y_test, multioutput='variance_weighted')

你会得到相同的结果.

这篇关于XGBRegressor score 方法返回奇怪的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆