Permutation Importance สำหรับ MLPClassifier
ในแบบฝึกหัดนี้ จะใช้ permutation importance เพื่อระบุว่าฟีเจอร์ใดมีผลต่อการพยากรณ์โรคหัวใจด้วย MLPClassifier มากที่สุด
X ที่บรรจุฟีเจอร์ และ y ที่บรรจุป้ายกำกับได้ถูกโหลดไว้ให้แล้ว รวมถึง matplotlib.pyplot ที่ import ในชื่อ plt
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Explainable AI ด้วย Python
คำแนะนำการฝึกหัด
- คำนวณ permutation importance โดยใช้ 10 รอบ และกำหนด
random_stateเป็น 1 - พล็อตความสำคัญของฟีเจอร์ด้วย bar plot
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
from sklearn.neural_network import MLPClassifier
from sklearn.inspection import permutation_importance
model = MLPClassifier(hidden_layer_sizes=(10), random_state=1)
model.fit(X, y)
# Compute the permutation importance
result = ____
# Plot feature importances
____
plt.xticks(rotation=45)
plt.show()