Permutation importance

Explainable AI ด้วย Python

Fouad Trad

Machine Learning Engineer

การสับโน้ตเพื่อหาความสำคัญของเครื่องดนตรีแต่ละชิ้น

ภาพวงดนตรีที่มีนักดนตรีกำลังเล่นเครื่องดนตรีต่างชนิด

Explainable AI ด้วย Python

Permutation importance

  • วิธีที่ไม่ขึ้นกับโมเดล
  • ประเมินความสำคัญของฟีเจอร์
    • วัดผลกระทบของการสับฟีเจอร์ต่อประสิทธิภาพ
  • ใช้ได้หลากหลาย

ภาพโครงสร้างโครงข่ายประสาทเทียม ประกอบด้วย hidden layer หลายชั้น แต่ละชั้นมีหลาย neuron

Explainable AI ด้วย Python

Permutation importance ในทางปฏิบัติ

ภาพชุดข้อมูลที่มี 5 ฟีเจอร์และโมเดล ML ที่เทรนแล้ว

Explainable AI ด้วย Python

Permutation importance ในทางปฏิบัติ

ภาพการนำชุดข้อมูลป้อนเข้าโมเดล ML เพื่อวัดประสิทธิภาพพื้นฐาน

Explainable AI ด้วย Python

Permutation importance ในทางปฏิบัติ

ภาพการสับค่าของฟีเจอร์หนึ่ง โดยค่าเดิมคือ [1, 2, 3, 4] และหลังสับเป็น [4, 2, 1, 3] จากนั้นนำชุดข้อมูลที่สับแล้วป้อนเข้าโมเดล ML เพื่อวัดประสิทธิภาพ

Explainable AI ด้วย Python

Permutation importance ในทางปฏิบัติ

ภาพแสดงว่าความสำคัญของฟีเจอร์ที่ถูกสับมีความสัมพันธ์กับการลดลงของประสิทธิภาพ

Explainable AI ด้วย Python

Permutation importance ในทางปฏิบัติ

ภาพแสดงว่าการลดลงมากบ่งชี้ความสำคัญสูง ส่วนการลดลงน้อยบ่งชี้ความสำคัญต่ำ

Explainable AI ด้วย Python

ชุดข้อมูลการรับเข้าเรียน

GRE Score TOEFL Score University Rating SOP LOR CGPA Chance of Admit Accept
337 118 4 4.5 4.5 9.65 0.92 1
324 107 4 4 4.5 8.87 0.76 1
316 104 3 3 3.5 8 0.72 1
322 110 3 3.5 2.5 8.67 0.8 1
314 103 2 2 3 8.21 0.45 0

 

ข้อมูลอยู่ใน: X_train, y_train

Explainable AI ด้วย Python

MLPClassifier

from sklearn.neural_network import MLPClassifier
model = MLPClassifier(hidden_layer_sizes=(10,10))

model.fit(X_train, y_train)
Explainable AI ด้วย Python

Permutation importance

from sklearn.inspection import permutation_importance

result = permutation_importance(model,
X_train, y_train,
n_repeats=10,
random_state=42,
scoring='accuracy')
print(result.importances_mean)
[0.16213568 0.13831658 0.10575377 0.10522613 0.11741206 0.20072864]
Explainable AI ด้วย Python

การแสดงผลความสำคัญ

import matplotlib.pyplot as plt
plt.bar(X_train.columns,
        result.importances_mean)

กราฟแท่ง permutation importance แสดงว่า CGPA มีความสำคัญสูงสุด

Explainable AI ด้วย Python

เปรียบเทียบกับวิธีที่ขึ้นกับโมเดล

import matplotlib.pyplot as plt
plt.bar(X_train.columns, 
        result.importances_mean)

กราฟแท่ง permutation importance แสดงว่า CGPA มีความสำคัญสูงสุด

Logistic regression
plt.bar(X_train.columns, np.abs(log_reg.coef_[0]))

กราฟแท่ง coefficient ของ logistic regression แสดงว่า CGPA มีความสำคัญสูงสุด

Explainable AI ด้วย Python

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

Explainable AI ด้วย Python

Preparing Video For Download...