From ddfbe2328300bc7ed401c20bb2aaedc72f055023 Mon Sep 17 00:00:00 2001 From: Brian Fannin Date: Tue, 22 May 2018 07:07:38 -0400 Subject: [PATCH] Closes #16 --- R/buildExplainer.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/buildExplainer.R b/R/buildExplainer.R index 7c086bb..7657d42 100644 --- a/R/buildExplainer.R +++ b/R/buildExplainer.R @@ -38,7 +38,7 @@ #' xgb.test.data <- xgb.DMatrix(test.data) #' #' param <- list(objective = "binary:logistic") -#' xgb.model <- xgboost(param =param, data = xgb.train.data, nrounds=3) +#' xgb.model <- xgboost(param = param, data = xgb.train.data, nrounds=3) #' #' col_names = colnames(X) #' @@ -47,20 +47,20 @@ #' 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_ntreelimit - 1) +#' explainer = buildExplainer(xgb.model, xgb.train.data, type="binary", base_score = 0.5) #' pred.breakdown = explainPredictions(xgb.model, explainer, xgb.test.data) #' #' showWaterfall(xgb.model, explainer, xgb.test.data, test.data, 2, type = "binary") #' showWaterfall(xgb.model, explainer, xgb.test.data, test.data, 8, type = "binary") -buildExplainer = function(xgb.model, trainingData, type = "binary", base_score = 0.5, n_first_tree = NULL){ +buildExplainer = function(xgb.model, trainingData, type = "binary", base_score = 0.5, n_first_tree = 1){ col_names = attr(trainingData, ".Dimnames")[[2]] cat('\nCreating the trees of the xgboost model...') trees = xgb.model.dt.tree(col_names, model = xgb.model, n_first_tree = n_first_tree) cat('\nGetting the leaf nodes for the training set observations...') - nodes.train = predict(xgb.model,trainingData,predleaf =TRUE) + nodes.train = predict(xgb.model, trainingData, predleaf = TRUE) cat('\nBuilding the Explainer...') cat('\nSTEP 1 of 2')