i712345
i712345

Reputation: 189

XGBRegressor score method returning strange values

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.

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

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

Upvotes: 3

Views: 7945

Answers (2)

gulshan madhur
gulshan madhur

Reputation: 21

You meant sample weight = None is replaced "uniform_average" and not multiouput param!

Upvotes: 0

Vivek Kumar
Vivek Kumar

Reputation: 36599

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

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

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

Try the below code:

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

And you will get identical results.

Upvotes: 9

Related Questions