Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find coefficients of model in XGBoost Regressor?

In XGBoost Regression to predict prices, How to get coefficients, intercepts of model? How to get summary of model like we get in Statsmodel for Linear regression? See below code

from xgboost import XGBRegressor
# fit model no training data
model = XGBRegressor()
model.fit(X_train, y_train)
# make predictions for test data
y_pred = model.predict(X_test)
print("R^2: {}".format(model.score(X_test, y_test)))
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print("Root Mean Squared Error: {}".format(rmse))

This is how I build the model and tried to get coefficients like this:

#print the intercept
print(model.intercept_)
AttributeError: Intercept (bias) is not defined for Booster type gbtree
print(model.coef_)
AttributeError: Coefficients are not defined for Booster type gbtree

Can someone please help me to solve this. Thanks.

like image 485
Shubham Chinchole Avatar asked Jul 31 '19 12:07

Shubham Chinchole


1 Answers

xgboost reference note on coef_ property:

Coefficients are only defined when the linear model is chosen as base learner (booster=gblinear). It is not defined for other base learner types, such as tree learners (booster=gbtree).

The default is booster=gbtree

like image 185
Vincent Snow Avatar answered Nov 29 '22 08:11

Vincent Snow