How to get non-bar SHAP plot for LightGBM

Question:

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

enter image description here

Now, I would like to see a SHAP plot like the following one:

enter image description here

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:

enter image description here

Does anybody know how to generate a plot similar to this one (for lightgbm – for xgboost the code works fine):

enter image description here

Asked By: Giampaolo Levorato

||

Answers:

shap.plots.beeswarm(shap_values)

Please check the documentation if needed.

Answered By: Rafa

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)
Answered By: Abhineet Gupta
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.