为什么 xgboost 没有绘制我的树? [英] Why is xgboost not plotting my trees?

查看:69
本文介绍了为什么 xgboost 没有绘制我的树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按如下方式运行 xgboost 模型:

I am running xgboost model as follows:

bst <- xgb.train(data=dtrain, booster="gbtree", objective="reg:linear",
    max.depth=5, nround=20, watchlist=watchlist,min_child_weight=10)
importance_matrix <- xgb.importance(names, model = bst)
xgb.plot.importance(importance_matrix[1:10,])

变量重要性矩阵绘制得很好,但是当我遵循

Variable-importance matrix is plotted nicely but when I do following

xgb.plot.tree(feature_names = names, model = bst, n_first_tree = 2)

RStudio 打开一个新的浏览器窗口并显示大量 HTML,但没有图像.HTML 包含所有细节,例如创建图形所需的脚本等.但我没有这些 java 脚本,我认为它应该像绘制重要性矩阵一样工作.

RStudio opens a new browser window and shows lots of HTML, but no image. The HTML has all the details like the scripts needed to create graphs etc. but I dont have these java scripts and I was thinking it should just work like plotting the importance-matrix.

我错过了什么?

推荐答案

如果一棵树只有一个节点,那么它不会被绘制,前两棵树就是这种情况.你可以先通过 xgb.dump 转储你的树,看看哪些树有多个节点,并相应地增加 n_first_tree 值.

If a tree has only one node then it will not be plotted, and that's the case for your first two trees. You can dump your tree first via xgb.dumpand see which trees have more than one node, and increase the n_first_tree value accordingly.

这篇关于为什么 xgboost 没有绘制我的树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆