Local explainability ด้วย SHAP

Explainable AI ด้วย Python

Fouad Trad

Machine Learning Engineer

Global vs. local explainability

Global explainability
  • พฤติกรรมโดยรวมของโมเดล
  • ไม่อธิบายแต่ละ instance

อาจารย์อธิบายผลการเรียนภาพรวมของห้องให้นักเรียนทุกคนฟัง

Local explainability
  • อธิบายการพยากรณ์สำหรับข้อมูลแต่ละจุด
  • สำคัญมากสำหรับงานที่มีความละเอียดอ่อน

อาจารย์อธิบายเหตุผลของคะแนนให้นักเรียนคนหนึ่งเป็นการเฉพาะ

1 Images generated by DALL-E
Explainable AI ด้วย Python

ชุดข้อมูลโรคหัวใจ

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 สำหรับพยากรณ์ความเสี่ยงโรคหัวใจ

Explainable AI ด้วย Python

Local explainability ด้วย SHAP

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)
Explainable AI ด้วย Python

SHAP waterfall plots

  • แสดงให้เห็นว่า feature แต่ละตัวเพิ่มหรือลดค่าพยากรณ์ของโมเดล

Waterfall plot แสดง feature หลายตัวและการมีส่วนร่วมของแต่ละตัวต่อผลพยากรณ์

Explainable AI ด้วย Python

SHAP waterfall plots

  • แสดงให้เห็นว่า feature แต่ละตัวเพิ่มหรือลดค่าพยากรณ์ของโมเดล

Waterfall plot เดิมแสดง baseline value ซึ่งเป็นจุดเริ่มต้นของการพยากรณ์

Explainable AI ด้วย Python

SHAP waterfall plots

  • แสดงให้เห็นว่า feature แต่ละตัวเพิ่มหรือลดค่าพยากรณ์ของโมเดล

Waterfall plot เดิมแสดงว่า feature ที่ดันไปทางขวาจะเพิ่มค่าพยากรณ์ ส่วน feature ที่ดันไปทางซ้ายจะลดค่าพยากรณ์

Explainable AI ด้วย Python

สร้าง waterfall plots

shap.waterfall_plot(

shap.Explanation(
values=shap_values[:,1],
base_values=explainer.expected_value[1],
data=test_instance,
feature_names=X.columns
)
)
Explainable AI ด้วย Python

Waterfall plots สำหรับหลาย instance

ภาพแสดง waterfall plots สี่กราฟ หนึ่งกราฟต่อหนึ่งตัวอย่าง เพื่อแสดงให้เห็นว่าแต่ละตัวอย่างมีรูปแบบที่แตกต่างกันในการนำไปสู่การตัดสินใจของโมเดล

Explainable AI ด้วย Python

มาฝึกกันเถอะ!

Explainable AI ด้วย Python

Preparing Video For Download...