【问题标题】:How to find coefficients of model in XGBoost Regressor?如何在 XGBoost Regressor 中找到模型的系数?
【发布时间】:2019-07-31 12:02:37
【问题描述】:

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

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))

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

#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

谁能帮我解决这个问题。谢谢。

【问题讨论】:

    标签: regression xgboost


    【解决方案1】:

    xgboost reference note on coef_ property:

    系数仅在选择线性模型作为基础学习者(Booster = Glinear)时定义。它没有为其他基础学习器类型定义,例如树学习器 (booster=gbtree)。

    默认是 booster=gbtree

    【讨论】:

    • 欢迎来到 SO!我已经赞成你的回答。如果您添加对它的任何引用,那就太好了。
    • 在 (booster=gblinear) 时如何访问系数?
    • @JanJaniszewski 只需用model.coef_拉出系数数组,完成后就可以与数据框列匹配。
    猜你喜欢
    • 1970-01-01
    • 2022-10-16
    • 2021-05-12
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 2021-09-23
    • 2022-12-23
    • 2020-01-03
    相关资源
    最近更新 更多