트리 기반 모델의 설명가능성

Python으로 배우는 Explainable AI

Fouad Trad

Machine Learning Engineer

의사결정나무

  • 트리 기반 모델의 기본 구성 요소
  • 회귀와 분류에 사용
  • 예측을 위한 트리 구조
    • 여러 결정
    • 각 결정은 하나의 특성에 기반
  • 본질적으로 설명 가능

여러 조건에 따라 예측이 이루어지는 의사결정나무의 표현

Python으로 배우는 Explainable AI

랜덤 포레스트

  • 여러 의사결정나무로 구성
  • 회귀와 분류에 사용
  • 직접 해석이 어려움
  • 특성 중요도
    • 예측 불확실성 감소량을 측정
    • 선형모형의 계수와 다름

랜덤 포레스트는 여러 나무의 집합으로 입력을 받아 예측을 집계해 최종 결과를 내는 그림

Python으로 배우는 Explainable AI

입학 데이터셋

GRE 점수 TOEFL 점수 대학 등급 SOP LOR CGPA 합격
337 118 4 4.5 4.5 9.65 1
324 107 4 4 4.5 8.87 1
316 104 3 3 3.5 8.00 1
322 110 3 3.5 2.5 8.67 1
314 103 2 2 3 8.21 0
X_train = data.drop(['Accept'], axis=1)
y_train = data['Accept']
Python으로 배우는 Explainable AI

모델 학습

from sklearn.tree import DecisionTreeClassifier

tree_model = DecisionTreeClassifier() tree_model.fit(X_train, y_train)
print(tree_model.feature_importances_)
[0.17936982 0.08878744 0.04388924 
 0.0532897  0.07130751 0.56335628]
from sklearn.ensemble import RandomForestClassifier

forest_model = RandomForestClassifier() forest_model.fit(X_train, y_train)
print(forest_model.feature_importances_)
[0.25347149 0.17518662 0.06551317 
 0.06758647 0.07866478 0.35957747]
Python으로 배우는 Explainable AI

특성 중요도

import matplotlib.pyplot as plt

plt.barh(X_train.columns, 
         tree_model.feature_importances_)
plt.title('Feature Importance - Decision Tree')
plt.show()

CGPA와 GRE 점수가 가장 중요한 특성임을 보여주는 가로 막대그래프.

import matplotlib.pyplot as plt

plt.barh(X_train.columns, 
         forest_model.feature_importances_)
plt.title('Feature Importance - Random Forest')
plt.show()

CGPA와 GRE 점수가 가장 중요한 특성임을 보여주는 가로 막대그래프.

Python으로 배우는 Explainable AI

연습해 봅시다!

Python으로 배우는 Explainable AI

Preparing Video For Download...