Description Usage Arguments Value Examples
View source: R/explainPredictions.R
This function outputs the feature impact breakdown of a set of predictions made using an lightgbm model.
1 | explainPredictions(lgb.model, explainer, data)
|
lgb.model |
A trained lightgbm model |
explainer |
The output from the buildExplainer function, for this model |
data |
A DMatrix of data to be explained |
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).
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.