AppliedDataSciencePartners / xgboostExplainer

An R package that makes xgboost models fully interpretable
GNU General Public License v3.0
252 stars 69 forks source link

buildExplainer error when running your example #16

Open zk117 opened 6 years ago

zk117 commented 6 years ago

library(xgboost)

library(xgboostExplainer)

set.seed(123)

data(agaricus.train, package='xgboost')

X = as.matrix(agaricus.train$data)

y = agaricus.train$label

train_idx = 1:5000

train.data = X[train_idx,]

test.data = X[-train_idx,]

xgb.train.data <- xgb.DMatrix(train.data, label = y[train_idx])

xgb.test.data <- xgb.DMatrix(test.data)

param <- list(objective = "binary:logistic")

xgb.model <- xgboost(param =param, data = xgb.train.data, nrounds=3) [1] train-error:0.000000 [2] train-error:0.000000 [3] train-error:0.000000

col_names = colnames(X)

pred.train = predict(xgb.model,X)

nodes.train = predict(xgb.model,X,predleaf =TRUE)

trees = xgb.model.dt.tree(col_names, model = xgb.model)

The XGBoost Explainer

explainer = buildExplainer(xgb.model,xgb.train.data, type="binary", base_score = 0.5, n_first_tree = xgb.model$best_ntr .... [TRUNCATED]

Creating the trees of the xgboost model...Error in parse(text = paste(new_par, "<-", pars[[pars_par]])) :

:2:0: unexpected end of input 1: trees <- ^ In addition: Warning message: 'n_first_tree' is deprecated. Use 'trees' instead. See help("Deprecated") and help("xgboost-deprecated"). Called from: parse(text = paste(new_par, "<-", pars[[pars_par]]))
amir-ghasemi commented 6 years ago

Having the same issue with xgboost 0.6.4.6

skamkar commented 6 years ago

As the error states, 'n_first_tree' has been deprecated by 'trees'. A simple input variable name substitution will resolve this discrepancy.

See here: https://github.com/AppliedDataSciencePartners/xgboostExplainer/blob/master/R/buildExplainer.R#L61

LegiSam commented 6 years ago

I also faced the same problem when I was using the Github version. To overcome this, I download the stable version (0.6.4.1) on CRAN and it worked without any problems.

PirateGrunt commented 6 years ago

I think the issue is to do with how the example code is written. It references a property of the xgboost model object best_ntreelimit which is only available when the early_stopping_rounds argument has been set in the call to xgboost().

Reindert94 commented 6 years ago

I faced the same problem when upgrading to xgboost version (0.71.1). Downgrading again to 0.6.4.1 (as LegiSam describes above) does the trick.