Why is xgboost not plotting my trees?

2019-04-07 01:04发布

问题:

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

What am I missing?

回答1:

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.



标签: r plot xgboost