Support categorical features in ranger.unify and gbm.unify#54
Draft
Copilot wants to merge 3 commits into
Draft
Conversation
Agent-Logs-Url: https://github.com/ModelOriented/treeshap/sessions/61e314b5-f54b-40a2-9ebf-df0bf86f2ec3 Co-authored-by: mayer79 <16206095+mayer79@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ModelOriented/treeshap/sessions/61e314b5-f54b-40a2-9ebf-df0bf86f2ec3 Co-authored-by: mayer79 <16206095+mayer79@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for categorical features in ranger and gbm unify
Support categorical features in May 13, 2026
ranger.unify and gbm.unify
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.
ranger.unifyandgbm.unifyrejected models trained on factor columns. This PR implements categorical split support across the full treeshap pipeline.Encoding convention
A new
decision_type = 3(displayed as"==") represents a categorical bitmask split. TheSplitvalue is a right-group bitmask: bitk-1set → factor levelkgoes to theNo(right) child. Factor columns in datasets are passed throughas.numeric(factor)(already done by existingsapply(x, as.numeric)calls), yielding 1-based integer codes.C++ traversal (
treeshap.cpp,set_reference_dataset.cpp,predict.cpp)Added
decision_type == 3branch to all three tree-walking functions:If the observation's level is not in the right-group bitmask → goes left (Yes child).
gbm.unifystop()that blocked categorical features.c.splitsindex stored inSplit, retrievesgbm_model$c.splits[[idx]], and computes a right-group bitmask (levels wherec_split[k] == 1go right). SetsDecision.type = "=="for those nodes.ranger.unify/ranger_unify.common!forest$is.ordered(per-feature unordered flag) from the ranger model and passes it intoranger_unify.common.treeInforeturns charactersplitval(partition mode), parses the comma-separated right-going level indices and computes the right-group bitmask. Threshold splits on ordered/numeric features in the same trees (also coerced to character by R) are handled byas.numeric()conversion.model_unified.Ris.model_unified()now acceptsc("<=", "<", "==")as a valid level set (backward-compatible with existing two-level models).SplitandDecision.typecolumn documentation.Usage
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cran.r-project.org/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either: