Explainable AI in Python
Fouad Trad
Machine Learning Engineer


| age | sex | chest_pain_type | blood_pressure | ecg_results | thalassemia | target |
|---|---|---|---|---|---|---|
| 52 | 1 | 0 | 125 | 1 | 3 | 0 |
| 53 | 1 | 0 | 140 | 0 | 3 | 0 |
| 70 | 1 | 0 | 145 | 1 | 3 | 0 |
| 61 | 1 | 0 | 148 | 1 | 3 | 0 |
| 62 | 0 | 0 | 138 | 1 | 2 | 0 |
knn: KNN classifier predicting risk of heart disease
explainer = shap.KernelExplainer(knn.predict_proba, shap.kmeans(X, 10))test_instance = X.iloc[0, :]shap_values = explainer.shap_values(test_instance)print(shap_values.shape)
(6, 2)



shap.waterfall_plot(shap.Explanation(values=shap_values[:,1],base_values=explainer.expected_value[1],data=test_instance,feature_names=X.columns))

Explainable AI in Python