dmlc / dmlc/xgboost

Plots for categorical splits don't show named categories

Open
#9,927 3 comments 0 reactions 0 assignees View on GitHub
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)
```
![image](https://github.com/dmlc/xgboost/assets/11860098/afdaa58d-f798-44b4-8cb9-bd6335c8100b)

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.