A fitted tree reveals which feature questions reduced label uncertainty, but a feature may appear at several depths. Feature importance collects that evidence into one comparable score per original input feature while giving broad, high-level splits more credit than tiny late branches.
Implement feature_importances(tree, input, labels, n_features). Re-route the original training data through the stored tree, compute each split's gain, accumulate its sample-weighted credit, and normalize the result.
tree was fit on the supplied input and labels; n_features is the full input width.(n_features,).(node_labels.size / total_samples) * information_gain(...) to the split feature.information_gain and do not mutate the tree or data.Open one at a time. Each gives away a little more than the last.
The tree stores split decisions, not the data that reached them; carry a data subset through a recursive walk.
At a split node, form left_mask from that node's feature and threshold, recurse on both masked subsets, and credit the current feature before recursing.
No results yet
Run your code to check it against the examples, or submit to run every test.