Is there any way to get samples in under each leaf of a decision tree in Sklearn ?

I have trained decision tree . I also have a graph of the tree ( ) . Now i want to see which samples (red circled ones ) are under which leafs . I am using sklearn's implantation . Is there any way to get the samples under a leaf ? ?

• Apply will only give you the leaf index, it doesn't explain how to get the array of y-values in that leaf Aug 5 '18 at 21:43

Very good and analytical answers are provided here and here.

For me, the easiest way would be to find the leaves where each sample belongs and then split the dataframe into clusters using iloc, to further analyse the clusters. This can be done using:

clf.apply(iris.data)


or

clf.predict(iris.data)


Yes,
Use the apply function on the fitted model.

See in Documents.

The mentioned leaf-index as the same as in the underlining _tree object(used for visualization).