2.3.4_Interpreting_ML Model

chang·2021년 3월 3일
0

부트캠프

목록 보기
27/28

[키워드]

  • PDP plot
  • SHAP value

[학습내용]

  • Feature Importance : 트리모델에 국한된 모형 설명 + 모델 성능에 중요한지 여부만 파악 가능

  • 모델의 종류와는 상관없는 모델 해석 방법인 model-agnostic 방법 ~>

    - Permutation Importance
    - PDP plot : 관심있는 특성들이 타겟에 어떻게 영향을 주는지 파악 가능
    - SHAP values : 단일 관측치로부터 특성들의 기여도 확인 가능

  • PDP plot의 사용

! pip install pdpbox
from pdpbox.pdp import pdp_isolate, pdp_plot

## 한 개 feature에 대한 PDP plot
feature = '관심 feature명'
isolated = pdp_isolate(
    model= 모델명, 
    dataset= 사용한 데이터셋
    model_features= 사용한 데이터셋의 변수들,
    feature=feature, # 관심 feature
    grid_type='percentile', # default='percentile', or 'equal'(이거로 하면 등간격)
    num_grid_points=10 # default=10
)
pdp_plot(isolated, feature_name=feature)

# 2 개의 관심 features에 대한 PDP interact plot

from pdpbox.pdp import pdp_interact, pdp_interact_plot

features = ['관심 feature1', '관심 feature2']
interaction = pdp_interact(
    model= 모델명, 
    dataset= 사용한 데이터셋,
    model_features= 사용한 데이터셋의 변수들, 
    features=features # 관심 변수들
)
  • SHAP value의 사용
! pip install shap # 코랩 환경에서는 설치부터 해주고
import shap

model = 모델(트리 모델로 가정)
row = X_test.iloc[[확인하고 싶은 열(인덱스 번호)]] 

explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(row)

shap.initjs()
shap.force_plot(
    base_value=explainer.expected_value, 
    shap_values=shap_values,
    features=row
)

[찾아볼 내용]👀

  • PDP plot과 ICE, Permutation Feature Importance, SHAP value의 비교

0개의 댓글