This is a test version of Biostars. For the public version, visit https://www.biostars.org.
plotting the tree in XGBoost

Dear all,

I am new in machine learning and used XGBoost classifier, while plotting the tree, I found 2 codes:

xgb.plot_tree(model, num_trees=5)
xgb.plot_tree(model)

What is the difference between both codes for plotting the tree?

By searching, I found that the first code for plotting the 5th boosted tree, but I couldn't understand.

Thanks in advance

xgboost

1 answer

You will get a number of trees as a result of (extreme) gradient tree boosting - the exact number depends on how many iterations were done before the training was stopped. Since there are almost always hundreds of trees (and sometimes thousands) in the final model, the plot_tree function will allow the printing of any of the trees.

The first line you show will print the 6th tree (tree index starts with 0). If you don't specify the num_trees parameter, it will plot the first tree (index 0). It is easy to find this information in API documentation for XGBoost.

Thanks a lot for this fruitful and helpful answer.

Log in to answer this question.