SHAP 설명 가능성

Python으로 배우는 Explainable AI

Fouad Trad

Machine Learning Engineer

SHAP 소개

  • SHAPSHapley Additive exPlanations
  • 모델 비의존적 기법
  • 게임 이론의 샤플리 값 사용
  • SHAP 값 → 예측에 대한 특성 기여도 정량화

SHAP 로고

Python으로 배우는 Explainable AI

밴드 멤버 간 수익 배분

밴드를 묘사한 이미지.

Python으로 배우는 Explainable AI

SHAP 설명자

 

  • SHAP 값 계산
  • 트리 설명자 → 트리 기반 모델

SHAP 설명자는 모든 모델에 적용 가능한 일반 설명자와 특정 모델 유형에 최적화된 유형별 설명자로 구분됨.

Python으로 배우는 Explainable AI

입학 데이터셋

GRE 점수 TOEFL 점수 대학 등급 SOP LOR CGPA 합격 확률 합격
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

 

  • rf_reg: 합격 확률 예측
  • rf_class: 합격 여부 예측
  • X: 특성을 담은 데이터프레임
Python으로 배우는 Explainable AI

SHAP 값 도출

import shap
회귀
explainer_reg = shap.TreeExplainer(rf_reg)

shap_values_reg = explainer_reg.shap_values(X)
분류
explainer_class = shap.TreeExplainer(rf_class)

shap_values_class = explainer_class.shap_values(X)
Python으로 배우는 Explainable AI

SHAP 출력 이해하기

회귀
print(shap_values_reg.shape)  
(400, 6)

SHAP 값이 X 데이터프레임과 같은 차원(표본 수, 특성 수)의 표로 표시됨

Python으로 배우는 Explainable AI

SHAP 출력 이해하기

회귀
print(shap_values_reg.shape)  
(400, 6)

SHAP 값이 X 데이터프레임과 같은 차원(표본 수, 특성 수)의 표로 표시됨

분류
print(shap_values_class.shape)
(400, 6, 2)

양성 클래스 값 선택

positive_values = shap_values_class[:,:,1]
Python으로 배우는 Explainable AI

특성 중요도

mean_shap_values_class = np.abs(shap_values_class[:, :, 1]).mean(axis=0)
mean_shap_values_reg = np.abs(shap_values_reg).mean(axis=0)

plt.bar(X_train.columns, mean_shap_values_class) plt.bar(X_train.columns, mean_shap_values_reg)

회귀와 분류의 특성 중요도를 보여주며, CGPA와 GRE 점수가 합격 예측에 가장 큰 영향을 미침을 강조함.

Python으로 배우는 Explainable AI

연습해 봅시다!

Python으로 배우는 Explainable AI

Preparing Video For Download...