Shu*_*ole 5 regression xgboost
在 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)
有人可以帮我解决这个问题。谢谢。
小智 6
系数仅在选择线性模型作为基础学习器 (booster=gblinear) 时才定义。它没有为其他基本学习器类型定义,例如树学习器 (booster=gbtree)。
默认为 booster=gbtree
| 归档时间: |
|
| 查看次数: |
4619 次 |
| 最近记录: |