dsgibbons / shap

A game theoretic approach to explain the output of any machine learning model.
https://shap-community.readthedocs.io/en/latest/
MIT License
25 stars 5 forks source link

BUG: waterfall color customisation #108

Open surbhi-gupta-drishya opened 1 year ago

surbhi-gupta-drishya commented 1 year ago

Issue Description

This issue is same as raised in here With default waterfall function, we are unable to change the color of waterfall plot. With this implementation all the existing functions will work "as is" with the enhancement of color customization. With this, the users of shap library can change the waterfall plot color as per their wish/requirement. Earlier they can see waterfall plot in Red and Blue color only: image

Minimal Reproducible Example

import pandas as pd
import numpy as np
import lightgbm as lgbm
import shap
temp = pd.DataFrame(np.random.randint(10,100,(100,10)),columns=["x_"+str(i) for i in range(10)])
temp["y"] = np.sum(temp.iloc[:,:8],axis=1) - np.sum(temp.iloc[:,8:],axis=1)

model = lgbm.LGBMRegressor(n_estimators=2, learning_rate=0.1)
X, y =temp.drop(["y"],axis=1), temp[["y"]]
model.fit(X,y )

explainer = shap.TreeExplainer(model)
idx=70
pred = model.predict(X.iloc[idx:idx+1])
shap_values = explainer(X.iloc[idx:idx+1])

shap.plots.waterfall(shap_values[0], max_display=10, show=False)

Expected Behavior

Color of water fall as defined by user.

Bug report checklist

Installed Versions

'0.42.1'