0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【物流AI #16】SHAPで物流AIの判断を可視化する:説明可能AI入門

0
Posted at

【物流AI #16】SHAPで物流AIの判断を可視化する:説明可能AI入門

なぜ説明可能性が必要か

「なぜこのルートを選んだか」「なぜ発注量が 80 個なのか」を人間が理解できないと、AI の信頼性が上がらず現場に浸透しない。SHAP は任意の ML モデルの予測を特徴量寄与度に分解する。

SHAP の基本:TreeExplainer(XGBoost)

import xgboost as xgb, shap, pandas as pd, numpy as np

# 需要予測モデル(XGBoost)
model = xgb.XGBRegressor(n_estimators=200)
model.fit(X_train, y_train)

# SHAP 値を計算
explainer = shap.TreeExplainer(model)
shap_vals = explainer.shap_values(X_test)   # (N, F)

# 重要度ランキング
shap.summary_plot(shap_vals, X_test,
                  feature_names=X_test.columns)

DeepExplainer(PyTorch 用)

ニューラルネットは DeepExplainerGradientExplainer を使う。

import shap, torch

background = X_train[:100]   # 背景サンプル
explainer  = shap.DeepExplainer(demand_model,
                                 torch.FloatTensor(background))
sv = explainer.shap_values(torch.FloatTensor(X_test[:10]))
# sv shape: (10, features)

個別予測の説明(Waterfall Plot)

# 予測 #3 の内訳
exp = shap.Explanation(
    values=shap_vals[3],
    base_values=explainer.expected_value,
    data=X_test.iloc[3],
    feature_names=list(X_test.columns)
)
shap.waterfall_plot(exp)

各特徴量が予測値をどれだけ押し上げ/押し下げたかを棒グラフで表示する。

RL エージェントへの適用

強化学習の行動値関数にも適用できる。

import shap, torch

def q_func(obs_array):
    with torch.no_grad():
        return model(torch.FloatTensor(obs_array)).numpy()

background  = obs_buffer[:200]
explainer   = shap.KernelExplainer(q_func, background)
sv          = explainer.shap_values(current_obs, nsamples=100)

print("行動選択に最も影響した特徴量:",
      feature_names[np.abs(sv).argmax()])

実運用での使い方

場面 使い方
発注量の根拠説明 Waterfall で担当者に提示
モデル改善 Summary で重要でない特徴量を削除
異常な予測の調査 外れ値 SHAP 値でバグ発見

shap.force_plot をダッシュボードに埋め込むとリアルタイム説明が可能。


シリーズ: 物流・倉庫 AI 実装ガイド 2026 (16/20)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?