Skip to content

Fix XGBoost categorical splits for CPU TreeExplainer with background - #2

Closed
04pallav wants to merge 2 commits into
masterfrom
fix/xgboost-categorical-cpu
Closed

Fix XGBoost categorical splits for CPU TreeExplainer with background#2
04pallav wants to merge 2 commits into
masterfrom
fix/xgboost-categorical-cpu

Conversation

@04pallav

@04pallav 04pallav commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add threshold_types=2 for XGBoost categorical splits (2^cat bitmask; in-set → right, not-in-set → left) in tree_shap.h and loader.
  • Convert pandas category columns to integer codes before _cext (_convert_xgboost_categorical_array), so tree routing matches XGBoost training.
  • Add TestExplainerXGBoostCategorical: background + tree_path_dependent additivity vs output_margin.

Fork-only PR — CPU path only. No _cext_gpu changes in this PR.

Design notes: contributor-notes/XGB_CATEGORICAL_FIX.md on branch personal/notes.

Not in this PR

Item Status
Interventional + categoricals Still NotImplementedError; needs tree_shap_indep categorical routing (shared LightGBM gap)
GPU (_cext_gpu) Deferred to GPU track — no changes here
Per-feature oracle vs pred_contribs Not tested — only row-level additivity vs output_margin

Test plan

  • pytest tests/explainers/test_tree.py::TestExplainerXGBoostCategorical
  • Manual 50-tree adult model: TreeEnsemble.predict and SHAP sums vs output_margin (~1e-6)
  • Per-feature comparison vs XGB pred_contribs (no-background path)

Add threshold_types=2 for XGB bitmask routing, convert pandas category columns to codes before _cext, and test additivity against output_margin.
Keep threshold_types=2 and cat-code conversion CPU-only until GPU track is validated.
@04pallav
04pallav force-pushed the fix/xgboost-categorical-cpu branch from 11a84aa to 92cbae5 Compare August 2, 2026 17:11
@04pallav

04pallav commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

Renamed branch to support/xgboost-categorical-cpu (support, not fix).

@04pallav 04pallav closed this Aug 2, 2026
@04pallav
04pallav deleted the fix/xgboost-categorical-cpu branch August 2, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant