Add Booster.compute_leaf_similarity() method #11926
Open
+111
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new method
Booster.compute_leaf_similarity()to compute similarity between observations based on leaf node co-occurrence across trees, similar to Random Forest proximity matrices.Closes #11919
API
Parameters:
data(DMatrix): Query dataset (m samples)reference(DMatrix): Reference dataset (n samples)weight_type(str):"gain"(default) or"cover"Returns:
ndarrayof shape (m, n) with values in [0, 1]Formula
Where:
Weight Types
Following the suggestion in #11919 to reuse feature importance definitions:
"gain"(default): Sum of loss reduction across all splits in the tree. Trees that contribute more to model improvement are weighted higher."cover": Sum of hessian values across all splits. For regression (hessian=1), this equals sample count. For classification (hessian=p(1-p)), this emphasizes trees that process more uncertain samples.Implementation Notes
pred_leaf=Trueandtrees_to_dataframe()Tests
Added
tests/python/test_leaf_similarity.pywith tests for:gainValueError