Skip to content

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

Description

@Jon77Ruler

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions