木系モデルの説明可能性

Pythonで学ぶExplainable AI

Fouad Trad

Machine Learning Engineer

決定木

  • 木系モデルの基本要素
  • 回帰と分類に利用
  • 予測のための木構造
    • 複数の分岐条件
    • 各分岐は1つの特徴に基づく
  • 本質的に説明可能

複数の条件に基づいてどのように予測するかを示す決定木の図

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

Passons à la pratique !

Pythonで学ぶExplainable AI

Preparing Video For Download...