Skip to content
Discussion options

You must be logged in to vote

Hi!

Thanks for your question!

You can get the leaf node index using the apply method of ShapeletTreeClassifier

For example:

import numpy as np
from wildboar.ensemble import ShapeletForestClassifier
from wildboar.datasets import load_gun_point

X, y = load_gun_point()
f = ShapeletForestClassifier()
f.fit(X, y)

# Get the index of the node where each sample ends up
# eg leaves[0] contains the leaf node index for the first sample
leaves = f.estimators_[0].apply(X)

# count which leaf has the most samples in it
np.unique(leaves, return_counts=True)

You can also request it for the forest:

leaves = f.apply(X)
leaves[0, 0] # the index of the leaf of the first sample in the first tree
leaves[:, 0] 

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by isaksamsten
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #83 on September 28, 2023 09:35.