dmlc / dmlc/xgboost

[R] xgb.cv doesn't return feature names

Open
#5,018 2 comments 0 reactions 1 assignee Claimed by @chyunsu3 View on GitHub
cross-validation type: bug type: r-package
Dominant language
C++
Stars
28.8k
Forks
8.9k
Avg merge
1d 12h
Merged PRs (30d)
54

Description

Hi all,

Long fan of your efforts with the Xgboost algorithm/implementation. It is super fast and memory-friendly.

I found a problem when trying to see feature importance when using the `xgb.cv` function, namely that it doesn't return the features names when using the callback `cb.cv.predict(save_models = TRUE)`.

I found this trying to plot the model importance using `xgb.plot.importance`.
Does the numbers refer to the python way of counting columns (i.e., starting from 0)?

I made an MRE below:

Xgboost version: xgboost_0.90.0.2 (R package)

```R
data(iris)
library(xgboost)
library(dplyr)

iris <- filter(iris, Species != 'setosa')
features <- as.matrix(iris[, !grepl('Species', colnames(iris))])
label <- ifelse(iris$Species == 'virginica', 1, 0)

model <- xgboost::xgb.cv(
data = features
, label = label
, nfold = 5
, nrounds = 25
, metrics = list("auc")
, stratified = TRUE
, verbose = TRUE
, callbacks = list(cb.cv.predict(save_models = TRUE))

, params = list(
eta = 0.1
, max_depth = 10
, objective = "binary:logistic"
, colsample_bytree = 0.5
, subsample = 0.5
, nthread = 2
, seed = 1
)
)

importance <- xgb.importance(model = model$models[[1]])
xgboost::xgb.plot.importance(importance)

```
![xgboost_reprex](https://user-images.githubusercontent.com/28371492/68325912-28129180-00a9-11ea-9a7e-23cfffc3f341.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.