Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildExplainer doesn't appear to work with current version of xgboost 1.7.7.1 #43

Open
Jon77Ruler opened this issue Mar 19, 2024 · 0 comments

Comments

@Jon77Ruler
Copy link

At step 2 of 2

Error in rbindlist(append(list(tree_breakdown), list(leaf_breakdown))) :
Item 2 has 4 columns, inconsistent with item 1 which has 2 columns. To fill missing columns use fill=TRUE.

Reproducible example:

library(xgboost)
library(mice)

set.seed(1)

df <- read.csv('https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.data.csv', header = F)
colnames(df) <- c('Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness',
                  'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age', 'Outcome')

df[2:8] <- lapply(df[2:8], function(x) replace(x, x %in% 0, NA))

micedf <- mice::mice(df)
df  <- mice::complete(micedf)

sample_size <- floor(0.75 * nrow(df))
train_index <- sample(seq_len(nrow(df)), size = sample_size)

train <- df[train_index,]
test <- df[-train_index,]

x <- train[, 1:8]
y <- train$Outcome
dtrain <- xgb.DMatrix(as.matrix(x), label = y)

xgbmodel <- xgboost(
  data = dtrain,
  nrounds = 42,
  params = list(
    objective = "binary:logistic",
    eta = 0.40,
    max_depth = 7,
    gamma = 0.83,
    colsample_bytree = 0.66,
    min_child_weight = 9,
    subsample = 0.44)
)

library(xgboostExplainer)

set.seed(1) # Reset random seed
xgb.preds <- predict(xgbmodel, dtrain)
explainer <- buildExplainer(xgbmodel, dtrain, type="binary",
                            base_score = 0.5, trees_idx = NULL)
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

No branches or pull requests

1 participant