I got an xgboost model after fitting. Then I used model.apply() with some testing data to get the leaf index :
testing data 0 : leaf index of tree 0 (e.g. 23), index of tree 1 (e.g. 17), .....
testing data 1 : leaf index of tree 0 (e.g. 16), index of tree 1 (e.g. 22), ..... ...
I also used xgboost.plot_tree to show tree 0. If max_depth of tree = 4, there are 31 nodes.
Manually calculate testing data 0 with decision tree 0, and got the leaf position.
It seems hard to link "the position of that leaf" and "previous leaf index" (e.g. 23).
Only description in website - https://xgboost.readthedocs.io/en/latest/python/python_api.html : "For each datapoint x in X and for each tree, return the index of the leaf x ends up in. Leaves are numbered within [0; 2**(self.max_depth+1)), possibly with gaps in the numbering."
How to interpret the leaf index in xgboost tree ?