buildExplainer error when running your example
zk117 opened this issue · 5 comments
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]]))
Having the same issue with xgboost 0.6.4.6
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
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.
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()
.
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.