% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/showWaterfall.R
\name{showWaterfall}
\alias{showWaterfall}
\title{Step 3: Get prediction breakdown and waterfall chart for a single row of data}
\usage{
showWaterfall(xgb.model, explainer, DMatrix, data.matrix, idx,
  type = "binary", threshold = 1e-04, limits = c(NA, NA))
}
\arguments{
\item{xgb.model}{A trained xgboost model}

\item{explainer}{The output from the buildExplainer function, for this model}

\item{DMatrix}{The DMatrix in which the row to be predicted is stored}

\item{data.matrix}{The matrix of data from which the DMatrix was built}

\item{idx}{The row number of the data to be explained}

\item{type}{The objective function of the model - either "binary" (for binary:logistic) or "regression" (for reg:linear)}

\item{threshold}{Default = 0.0001. The waterfall chart will group all variables with absolute impact less than the threshold into a variable called 'Other'}

\item{limits}{The limits of the y axis - for binary this is on logit scale (e.g. c(-3,3) would give a scale approximately from 0.04 to 0.96)}
}
\value{
None
}
\description{
This function prints the feature impact breakdown for a single data row, and plots an accompanying waterfall chart.
}
\examples{
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)

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, trees = NULL)
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")
}
