Skip to content

lantanacamara/lightgbmExplainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

lightgbmExplainer

An R package that makes LightGBM models fully interpretable

Example

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")

Take reference from xgboostExplainer and credit to David Foster.

Note: LightGBM provides similar function lgb.interprete and lgb.plot.interpretation. lgb.interprete could be faster if you only want to interprete a few data point, but it could be much slower if you want to interprete many data point.

About

An R package that makes lightgbm models fully interpretable (take reference from https://github.com/AppliedDataSciencePartners/xgboostExplainer)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages