SHAP 커널 설명자

Python으로 배우는 Explainable AI

Fouad Trad

Machine Learning Engineer

SHAP 커널 설명자

 

  • 어떤 모델에도 SHAP 값을 산출

    • K-최근접 이웃
    • 신경망
    • 트리 기반 모델
  • 유형별 설명자보다 느림

SHAP 설명자가 모든 모델에 적용 가능한 일반 설명자와 특정 모델 유형에 최적화된 유형별 설명자로 나뉨을 보여주는 이미지.

Python으로 배우는 Explainable AI

심장병

age sex chest_pain_type blood_pressure ecg_results thalassemia target
52 1 0 125 1 3 0
53 1 0 140 0 3 0
70 1 0 145 1 3 0
61 1 0 148 1 3 0
62 0 0 138 1 2 0

 

mlp_clf: 심장병 위험을 예측하는 다층 퍼셉트론

Python으로 배우는 Explainable AI

보험 요금

age gender bmi children smoker charges
19 0 27.900 0 1 16884.92
18 1 33.770 1 0 1725.55
28 1 33.000 3 0 4449.46
33 1 22.705 0 0 21984.47
32 1 28.880 0 0 3866.85

 

mlp_reg: 보험료를 예측하는 다층 퍼셉트론

Python으로 배우는 Explainable AI

커널 설명자 생성

MLPRegressor
import shap


explainer = shap.KernelExplainer( # 모델 예측 함수, # 데이터셋의 대표 요약 )
MLPClassifier
import shap


explainer = shap.KernelExplainer( # 모델 예측 함수, # 데이터셋의 대표 요약 )
Python으로 배우는 Explainable AI

커널 설명자 생성

MLPRegressor
import shap

explainer = shap.KernelExplainer(
  mlp_reg.predict, 
  # 데이터셋의 대표 요약
)


MLPClassifier
import shap

explainer = shap.KernelExplainer(
  mlp_clf.predict_proba, 
  # 데이터셋의 대표 요약
)


Python으로 배우는 Explainable AI

커널 설명자 생성

MLPRegressor
import shap

explainer = shap.KernelExplainer(
  mlp_reg.predict, 
  shap.kmeans(X, 10)
)


shap_values_reg = explainer.shap_values(X)
MLPClassifier
import shap

explainer = shap.KernelExplainer(
  mlp_clf.predict_proba, 
  shap.kmeans(X, 10)
)


shap_values_cls = explainer.shap_values(X)
Python으로 배우는 Explainable AI

특성 중요도

MLPRegressor
mean_reg = np.abs(shap_values_reg).mean(axis=0)

plt.bar(X.columns, mean_reg)

회귀 작업에서 특성 중요도 막대그래프. 흡연과 나이가 요금 예측에 가장 영향력이 큼.

MLPClassifier
mean_cls = np.abs(shap_values_cls[:,:,1]).mean(axis=0)

plt.bar(X.columns, mean_cls)

분류 작업에서 특성 중요도 막대그래프. 흉통 유형과 지중해빈혈이 요금 예측에 가장 영향력이 큼.

Python으로 배우는 Explainable AI

모델별 접근과 비교

선형 회귀
plt.bar(X.columns, np.abs(lin_reg.coef_))

선형 회귀 모델의 특성 중요도 막대그래프. 흡연과 나이가 요금 예측에 가장 영향력이 큼.

로지스틱 회귀
plt.bar(X.columns, np.abs(log_reg.coef_[0]))

분류 작업에서의 특성 중요도 막대그래프. 흉통 유형이 요금 예측에 가장 영향력이 큼.

Python으로 배우는 Explainable AI

연습해 봅시다!

Python으로 배우는 Explainable AI

Preparing Video For Download...