小编Shu*_*ole的帖子

如何在 XGBoost Regressor 中找到模型的系数?

在 XGBoost 回归中预测价格,如何获得模型的系数、截距?如何像我们在 Statsmodel 中获得的线性回归模型一样获得模型摘要?看下面的代码

from xgboost import XGBRegressor
Run Code Online (Sandbox Code Playgroud)
# fit model no training data
model = XGBRegressor()
model.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
# make predictions for test data
y_pred = model.predict(X_test)
Run Code Online (Sandbox Code Playgroud)
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))
Run Code Online (Sandbox Code Playgroud)

这就是我构建模型并尝试获得这样的系数的方式:

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

有人可以帮我解决这个问题。谢谢。

regression xgboost

5
推荐指数
1
解决办法
4619
查看次数

标签 统计

regression ×1

xgboost ×1