Plots for categorical splits don't show named categories
- Dominant language
- C++
- Stars
- 28.8k
- Forks
- 8.9k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 54
Description
When producing a plot of a tree with categorical splits, the plots will use the numbers of the categories:
```python
import numpy as np, xgboost as xgb
rng = np.random.default_rng(seed=123)
X = rng.integers(4, size=(100,3))
y = rng.standard_normal(size=100)
dm = xgb.DMatrix(
data=X,
label=y,
feature_types=["c"]*3
)
model = xgb.train(
dtrain=dm,
params={
"tree_method" : "hist",
"max_depth" : 2
},
num_boost_round=3
)
xgb.plot_tree(model)
```

Categorical features typically have named categories. Would be quite helpful to show those on the plots instead of the numbers, which might not be easy to mentally map to a given category.
For this, I guess that a potential solution could be to add an additional dmatrix/booster string attribure for "categorical_names" or so, like there is a "feature_name".
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the categorical-split plotting path from xgb.plot_tree and the DMatrix/Booster metadata mentioned in the issue. Run the provided example, then determine how category names could be supplied and preserved; done means categorical plots show names instead of numeric codes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100