MLPClassifier 的置換重要度(Permutation importance)
你的任務是使用置換重要度來找出,在使用 MLPClassifier 預測心臟疾病時,哪些特徵影響最大。
已為你預先載入含有特徵的 X 與含有標籤的 y。matplotlib.pyplot 也已以 plt 名稱匯入。
本練習屬於課程
Python 的 Explainable AI
練習說明
- 使用
random_state設為 1,並進行 10 次重複,計算置換重要度。 - 以長條圖繪製特徵重要度。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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()