[R] Cannot plot trees with categorical splits
- Dominant language
- C++
- Stars
- 28.8k
- Forks
- 8.9k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 54
Description
ref https://github.com/dmlc/xgboost/issues/9810
Currently, attempting to plot trees that have categorical splits in R will result in an error:
```r
library(xgboost)
set.seed(123)
y <- rnorm(100)
x <- sample(3, size=100*3, replace=TRUE) |> matrix(nrow=100)
x <- x - 1
dm <- xgb.DMatrix(data=x, label=y)
setinfo(dm, "feature_type", c("c", "c", "c"))
model <- xgb.train(
data=dm,
params=list(
tree_method="hist",
max_depth=3
),
nrounds=2
)
xgb.plot.tree(model=model)
````
```
Error in do.call(rbind, matches)[, c(2, 3, 5, 6, 7, 8, 10), drop = FALSE] :
subscript out of bounds
```
This is due to the regexes used to parse the dumps not having been updated for the format used in categorical splits:
https://github.com/dmlc/xgboost/blob/a197899161fa70e681101de4232745fdfe737804/R-package/R/xgb.model.dt.tree.R#L123
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with R-package/R/xgb.model.dt.tree.R at the dump-parsing regexes around line 123, then run the categorical-split example from the issue and reproduce the xgb.plot.tree error. Done means xgb.plot.tree(model=model) parses and plots trees with categorical splits without the subscript-out-of-bounds error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100