Skip to content

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

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

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

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)

@04pallav
04pallav force-pushed the fix/xgboost-categorical-gpu branch from 29872d0 to fdd1adc Compare August 2, 2026 16:54
Add threshold_types=2 for XGB bitmask routing, convert pandas category columns to codes before _cext, and test additivity against output_margin.
@04pallav
04pallav force-pushed the fix/xgboost-categorical-gpu branch from fdd1adc to 0cea3f8 Compare August 2, 2026 16:56
Keep threshold_types=2 and cat-code conversion CPU-only until GPU track is validated.
@04pallav

04pallav commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

Renamed branch to fix/xgboost-categorical-cpu (CPU-only scope).

@04pallav 04pallav closed this Aug 2, 2026
@04pallav
04pallav deleted the fix/xgboost-categorical-gpu branch August 2, 2026 17:03
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