I have trained decision tree . I also have a graph of the tree ( enter image description here) . 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 ? ?

  • 1
    $\begingroup$ Apply will only give you the leaf index, it doesn't explain how to get the array of y-values in that leaf $\endgroup$
    – pkdmark
    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:




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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.