lightgbmExplainer icon indicating copy to clipboard operation
lightgbmExplainer copied to clipboard

Error in explained probability

Open Dmirijs-Ozernovs opened this issue 5 years ago • 2 comments

Hi! I found an error between predicted probability and probability derived from the explainer. In the sample data set (agaricus) it is between -0.015 and -0.017. For other data sets error could be higher than 0.1. Is it normal or there are ways to avoid this error?

Reproducible example:

library(lightgbm) # v2.1.0 or above library(lightgbmExplainer) set.seed(12345)

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

should be close to zero

predict(lgb.model,agaricus.train$data)[8] - (exp(sum(pred.breakdown[8,]))/(exp(sum(pred.breakdown[8,])) + 1))

obvious bias in errors

plot(predict(lgb.model,agaricus.train$data) - (exp(rowSums(pred.breakdown))/(exp(rowSums(pred.breakdown)) + 1)))

Dmirijs-Ozernovs avatar Nov 30 '20 22:11 Dmirijs-Ozernovs

Hi, Now lightgbm has already provided lgb.plot.interpretation()

You might want to use that

alberthkcheng avatar Dec 04 '20 15:12 alberthkcheng

Hi, Now lightgbm has already provided lgb.plot.interpretation()

You might want to use that

Thank you! Have missed it, will make my own waterfall chart from the results.

Dmirijs-Ozernovs avatar Dec 04 '20 20:12 Dmirijs-Ozernovs