Explainable AI in Python
Fouad Trad
Machine Learning Engineer
| age | gender | bmi | children | smoker | charges |
|---|---|---|---|---|---|
| 19 | 0 | 27.900 | 0 | 1 | 16884.92 |
| 18 | 1 | 33.770 | 1 | 0 | 1725.55 |
| 28 | 1 | 33.000 | 3 | 0 | 4449.46 |
| 33 | 1 | 22.705 | 0 | 0 | 21984.47 |
| 32 | 1 | 28.880 | 0 | 0 | 3866.85 |
model: random forest regressor to predict charges
import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)
shap.summary_plot(shap_values, X, plot_type="bar")



shap.summary_plot(shap_values, X,
plot_type="dot")


shap.partial_dependence_plot("age",
model.predict,
X)

For each sample:
Average results from all samples
shap.partial_dependence_plot("age",
model.predict,
X)

Explainable AI in Python