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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With