Repository navigation
Conversation
interaction_cst in trees and downstream ensemble models
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add support for
interaction_cstin decision trees and downstream ensemble models.Reference Issues/PRs
I did not find issues explicitly asking for this, but I was asked for it in a freelance project (and we agreed on making it open-source).
This helps with issue #27873 because HGB already supports
interaction_cst, so this PR brings GB one step closer to HGB.What does this implement/fix? Explain your changes.
API changes:
Adds a new
interaction_cstparameter to:<Decision/Extra>Tree<Classifier/Regressor><RandomForest/ExtraTrees/GradientBoosting><Classifier/Regressor>The
interaction_cstparameter supports the same options as in HGB:"pairwise"shorthand,"no_interactions"shorthand.It's validated and normalized in
BaseDecisionTree.Logic of the implementation:
splitter.features, forbidden features are moved to the suffix and excluded from future draws.Implementation details
The interaction-constraint logic is encapsulated in a dedicated Cython class:
InteractionConstraints(insklearn/tree/_tree.pyx).It builds and stores group <-> feature mappings in both directions so updates after each split are efficient.
At fit time it also allocates:
The core method is
update_after_split(..., split_feature). It updates the active groups and moves newly forbidden features to the tail ofsplitter.features.It then persists state by writing
n_active_interaction_groupsandn_allowed_featuresto the parent record.Integration points in existing code paths are intentionally small:
_splitter.pyx): feature sampling is restricted tofeatures[:n_allowed_features].and children inherit the updated state.
node state by replaying ancestor split features through stored parent links.
Test coverage added/updated:
For trees:
best/randomsplitters, dense/sparse inputs,"no_interactions"removes mixed second-order effects.+ Ensemble smoke tests for Random Forest / Extra Trees / Gradient Boosting to verify parameter plumbing.
AI usage disclosure
I used AI assistance for:
The human part is: research, understanding, designing.
Benchmarks
Except for pathological cases I don't expect to see in the real world, providing interactions constraints has no negative impact on fit time. In most cases, it will reduce fit time because it reduces the number candidate splits.
I can provide detailed benchmark results using the script below if needed (including some pathological/near-pathological cases):
Details