简体   繁体   English

有没有办法在python中打印一个XGBoostRegressor树?

[英]Is there a way to print one XGBoostRegressor tree in python?

I have constructed a XGBoostRegressor model where I now want to try and plot one of the trees. 我已经构建了XGBoostRegressor模型,现在我想在其中尝试绘制其中一棵树。 I know that regular xgb classifier has the function plot_tree but unfortunately XGBoostRegressor does not. 我知道常规的xgb分类器具有plot_tree函数,但不幸的是XGBoostRegressor没有。 Is there any other way to plot the tree? 还有其他方法可以绘制树吗? I also tried importing plot_tree from xgboost and use plot_tree(xgb) which returns 我也尝试从xgboost导入plot_tree并使用plot_tree(xgb)返回

ValueError('Unable to parse node: 44['product_family'])

Any ideas if there is any other way in doing this? 有没有其他想法可以做到这一点?

I found the error, I had some whitespace in some of my feature names. 我发现了错误,我的某些功能名称中有一些空格。 I added the following line 我添加了以下行

    df.columns = df.columns.str.replace(" ", "_")

And now it worked to use the plot_tree(xgb). 现在可以使用plot_tree(xgb)了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM