Reputation: 1622
I have trained a lightGBM model using this code:
from flaml import AutoML
#Select Hyper-Parameters
automl_final = AutoML()
automl_final.fit(
X_train,
y_train,
estimator_list=["lgbm"],#,"xgboost"],
task="classification",
metric="roc_auc",
eval_method="cv",
n_splits=3,
time_budget=30,
sample=True,
append_log=True,
log_type="all",
model_history=True,
log_training_metric=True,
verbose=3,
seed=1234,
early_stop=True
)
Then I have generated a SHAP bar plot using this code:
lgbm = automl_final.model.estimator
explainer = shap.TreeExplainer(lgbm)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test,plot_type="bar")
And I got this plot (as expected):
Now, I would like to see a SHAP plot like the following one:
So I have used this code instead:
shap.summary_plot(shap_values, X_test)
And I still get the same SHAP bar-chart plot as before:
Does anybody know how to generate a plot similar to this one (for lightgbm - for xgboost the code works fine):
Upvotes: 1
Views: 919
Reputation: 31
Since you have trained a classification model, running shap_values = explainer.shap_values(X_test)
will return an array with two sets of shap values for predicting each of class=0 and class=1. This is why when you run shap.summary_plot(shap_values, X_test)
you get a bar chart with two bars for class=0 and class=1. To get a beeswarm summary plot of shap values for the prediction of class=1, you run:
shap.summary_plot(shap_values[1], X_test)
That will give you the output you're looking for.
Upvotes: 3
Reputation: 629
For a binary class lgbm model, use the shap values for one class to generate plot -
lgbm = automl_final.model.estimator
explainer = shap.TreeExplainer(lgbm)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values[1], X_test)
Upvotes: 2
Reputation: 684
shap.plots.beeswarm(shap_values)
Please check the documentation if needed.
Upvotes: 0