gpt4 book ai didi

regression - 如何在XGBoost回归器中找到模型系数?

转载 作者:行者123 更新时间:2023-12-03 16:13:06 27 4
gpt4 key购买 nike

在XGBoost回归中预测价格,如何获取系数,模型的截距?像我们在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

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

最佳答案

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


默认值为booster = gbtree

关于regression - 如何在XGBoost回归器中找到模型系数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57290314/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com