LIME によるローカル解釈性

Pythonで学ぶExplainable AI

Fouad Trad

Machine Learning Engineer

  • LIMELocal Interpretable Model-Agnostic Explanations
  • 複雑なモデルの予測を説明
  • 個々のインスタンスで動作
  • モデル非依存

LIME のロゴ。

Pythonで学ぶExplainable AI

LIME の Explainer

  • さまざまなデータに対応

利用可能な LIME Explainer の図。最初は表形式の Explainer。

Pythonで学ぶExplainable AI

LIME の Explainer

  • さまざまなデータに対応

同じ図で Text Explainer も表示。

Pythonで学ぶExplainable AI

LIME の Explainer

  • さまざまなデータに対応
  • サンプル周辺で摂動を生成
  • モデル出力への影響を評価
  • 説明用に単純なモデルを構築

同じ図で Image Explainer も表示。

Pythonで学ぶExplainable AI

LIME の Explainer

  • さまざまなデータに対応
  • サンプル周辺で摂動を生成
  • モデル出力への影響を評価
  • 説明用に単純なモデルを構築

表形式の Explainer が強調表示された同じ図。

Pythonで学ぶExplainable AI

入学審査データセット

GRE Score TOEFL Score University Rating SOP LOR CGPA Chance of Admit Accept
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

 

  • regressor: 合格確率を予測
  • classifier: 合否を予測
  • 特徴量は X に含む
Pythonで学ぶExplainable AI

表形式 Explainer の作成

回帰
from lime.lime_tabular import LimeTabularExplainer

instance = X.iloc[1,:]
explainer_reg = LimeTabularExplainer( X.values,
feature_names=X.columns,
mode='regression'
)
explanation_reg = explainer_reg.explain_instance(
instance.values,
regressor.predict
)
分類
from lime.lime_tabular import LimeTabularExplainer

instance = X.iloc[1,:]
explainer_class = LimeTabularExplainer( X.values,
feature_names=X.columns,
mode='classification'
)
explanation_class = explainer_class.explain_instance(
instance.values,
classifier.predict_proba
)
Pythonで学ぶExplainable AI

説明の可視化

回帰
explanation_reg.as_pyplot_figure()

各特徴量が回帰モデルに与える影響を示す棒グラフ。解釈しやすいよう範囲で配置。

分類
explanation_class.as_pyplot_figure()

各特徴量が分類モデルに与える影響を示す棒グラフ。解釈しやすいよう範囲で配置。

Pythonで学ぶExplainable AI

SHAP と LIME の比較

SHAP
shap.waterfall_plot(...)

各特徴量が予測を正負どちらに押すかを示す SHAP のウォーターフォール図。

LIME
explanation_class.as_pyplot_figure()

各特徴量が分類モデルに与える影響を示す棒グラフ。解釈しやすいよう範囲で配置。

Pythonで学ぶExplainable AI

練習してみましょう!

Pythonで学ぶExplainable AI

Preparing Video For Download...