explainPredictions: Step 2: Get multiple prediction breakdowns from a trained...

Description Usage Arguments Value Examples

View source: R/explainPredictions.R

Description

This function outputs the feature impact breakdown of a set of predictions made using an lightgbm model.

Usage

1
explainPredictions(lgb.model, explainer, data)

Arguments

lgb.model

A trained lightgbm model

explainer

The output from the buildExplainer function, for this model

data

A DMatrix of data to be explained

Value

A data table where each row is an observation in the data and each column is the impact of each feature on the prediction.

The sum of the row equals the prediction of the lightgbm model for this observation (log-odds if binary response).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(lightgbm) # v2.1.0 or above
library(lightgbmExplainer)

# Load Data
data(agaricus.train, package = "lightgbm")
# Train a model
lgb.dtrain <- lgb.Dataset(agaricus.train$data, label = agaricus.train$label)
lgb.params <- list(objective = "binary")
lgb.model <- lgb.train(lgb.params, lgb.dtrain, 5)
# Build Explainer
lgb.trees <- lgb.model.dt.tree(lgb.model) # First get a lgb tree
explainer <- buildExplainer(lgb.trees)
# compute contribution for each data point
pred.breakdown <- explainPredictions(lgb.model, explainer, agaricus.train$data)
# Show waterfall for the 8th observation
showWaterfall(lgb.model, explainer, lgb.dtrain, agaricus.train$data,  8, type = "binary")

lantanacamara/lightgbmExplainer documentation built on July 27, 2018, 2:06 a.m.