Shap: LightGBM classifier can have negative base value?

Created on 13 Aug 2018  路  15Comments  路  Source: slundberg/shap

Could the base values be negative on classification? Also the output on shap.force_plot doesn't match what I get from lgb.predict_proba....
I'd be happy to share the kernel or write a simpler test case if that helps.

Kaggle has some old version of shap but I get the same locally with 0.21.0
screenshot from 2018-08-13 10-13-31

Most helpful comment

It is important to keep in mind that LightGBM trees are built on the log-odds scale and then just transformed to probabilities for predict_proba. So SHAP values are also in log odds units. A negative base value means you are more likely class 0 than 1, and the sum will equal the log-odds output of the model not the transformed probability after the logistic function. Hope that is helpful!

All 15 comments

It is important to keep in mind that LightGBM trees are built on the log-odds scale and then just transformed to probabilities for predict_proba. So SHAP values are also in log odds units. A negative base value means you are more likely class 0 than 1, and the sum will equal the log-odds output of the model not the transformed probability after the logistic function. Hope that is helpful!

Thanks heaps for the clarification Scott!
Lame me, I can easily reproduce the lgb output by using the inverse logit of the shap_values' sum (+base value)!

Amazing work btw! Thanks for sharing this lib and the research behind it.

@henrique Were you able to generate force plots with the probabilities instead of log odds with lgb? Would you mind sharing code if so?

The kernel is here https://www.kaggle.com/hmendonca/lightgbm-predictions-explained-with-shap-0-796
But it uses the logit outputs. I think you could change the code to sigmoid the values before plotting them, bringing it to a linear 0-1 scale but it doesn't really matter that much if you just want to see the contributions, does it?

Thanks @henrique , that was very useful!

I should note that you can directly go to probability space now by using TreeExplainer's feature_dependence="independent" and model_output="probability" options. You can also transform the x-axis labels of the force plot from log odds to probabilities (while leaving the bar widths still in log odds) by using the link="logit" option of force_plot.

It is important to keep in mind that LightGBM trees are built on the log-odds scale and then just transformed to probabilities for predict_proba. So SHAP values are also in log odds units. A negative base value means you are more likely class 0 than 1, and the sum will equal the log-odds output of the model not the transformed probability after the logistic function. Hope that is helpful!

Thanks for the explanation but what does a negative value tell when we have more than 2 classes.

If you are going into a softmax then it is important to remember that the softmax is invariant to constant offsets added to the margin of all the classes. That means 0 does not need to be special, it is just the relation to other values that matters. However, if you were to subtract the mean margin from all classes then a negative value would just mean that class has a below average likelihood.

@henrique
I met the same problem. And tried all methods above. but the result is not probability
1
FD2C1F53-5121-11E9-A5D6-B8CA3AB540C7

I think whether the method lightgbm.train do not have the function predict_proba

@NancyLele that looks like it will produce probabilities, so perhaps share the plot you get?

@slundberg
11577DE4-55E2-11E9-9B80-B8CA3AB540C7
the above picture is result. The result is 0 or 1,not the probability

I think your results are in probability space. Try printing the result of predict_proba of your model for this same example. I believe they will be the same. Also, plot the force_plot for a few more examples in your dataset to make sure you understand the results.

@SaadAhmed96
The result of model.predict () is probability. The lightgbm.train() has not predict_proba function ,only has predict() function. I print the result of predict of my model,the result is 0.24. And I try more examples in my dataset .The reuslt of force_plot is 0 or 1,not the probability. So I don't know have to show probability in force_plot

Sorry, should have seen it earlier! I tried it on my own binary classification dataset and the results are in probability. In your code, you have added to 3 more arguments in the TreeExplainer change it to TreeExplainer(model) only and than try plotting again.

Thanks @SaadAhmed96

@NancyLele the output of lightgbm_model.predict(predict_) should be the same as shap_values.sum(1) + explainer.expected_value when using model_output='probability'. If it is not then please post a self contained example so we can debug it :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cbeauhilton picture cbeauhilton  路  3Comments

Nithanaroy picture Nithanaroy  路  4Comments

resdntalien picture resdntalien  路  3Comments

ArpitSisodia picture ArpitSisodia  路  3Comments

GitAnalyst picture GitAnalyst  路  3Comments