有没有办法在 python 中打印一个 XGBoostRegressor 树?
Is there a way to print one XGBoostRegressor tree in python?
我构建了一个 XGBoostRegressor 模型,现在我想尝试绘制其中一棵树。我知道常规 xgb 分类器具有 plot_tree 功能,但不幸的是 XGBoostRegressor 没有。还有其他方法可以绘制树吗?我还尝试从 xgboost 导入 plot_tree 并使用 plot_tree(xgb) which returns
ValueError('Unable to parse node: 44['product_family'])
有没有其他方法可以做到这一点?
我发现了错误,我的一些功能名称中有一些空格。我添加了以下行
df.columns = df.columns.str.replace(" ", "_")
现在可以使用 plot_tree(xgb)。
我构建了一个 XGBoostRegressor 模型,现在我想尝试绘制其中一棵树。我知道常规 xgb 分类器具有 plot_tree 功能,但不幸的是 XGBoostRegressor 没有。还有其他方法可以绘制树吗?我还尝试从 xgboost 导入 plot_tree 并使用 plot_tree(xgb) which returns
ValueError('Unable to parse node: 44['product_family'])
有没有其他方法可以做到这一点?
我发现了错误,我的一些功能名称中有一些空格。我添加了以下行
df.columns = df.columns.str.replace(" ", "_")
现在可以使用 plot_tree(xgb)。