계수 vs. 순열 중요도
이번에는 heart disease 데이터셋에 대해 학습된 로지스틱 회귀의 모델 계수와, 순열 중요도로 파악한 패턴을 비교해 보겠습니다. 스크립트 마지막에서 보조 함수 plot_importances()가 호출되어 동일한 플롯에 중요도를 그려 줍니다.
특성을 담은 X, 레이블을 담은 y, 그리고 로지스틱 회귀 model이 미리 로드되어 있습니다. matplotlib.pyplot은 plt로 임포트되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 Explainable AI
연습 안내
- 로지스틱 회귀
model의 계수를 계산하세요. random_state를 1로 두고, 20회 반복으로 순열 중요도를 계산하세요.- 모든 반복에 걸친 평균 순열 중요도를 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
from sklearn.inspection import permutation_importance
# Extract and store model coefficients
coefficients = ____
# Compute permutation importance on the test set
perm_importance = ____
# Compute the average permutation importance
avg_perm_importance = ____
plot_importances(coefficients, avg_perm_importance)