ICE 曲線付き部分依存プロット

ロットの予測廃棄率が機械速度と前回保守からの日数によってどう変わるか。ロットごとの曲線(ICE)に重ねた平均(PDP)で示します。

ICE 曲線付き部分依存プロット

部分依存プロット(PDP)は、ほかの特徴量を観測値のまま保ち、1 つの特徴量を動かしたときに、モデルの予測が平均してどう変わるかを示します。その平均の背後には、観測値ごとに 1 本ずつの 個別条件付き期待値(ICE)曲線があります。ICE 曲線が平行なら効果は全員に共通、広がったり交差したりすれば、平均が隠している 交互作用 が現れています。ICE 曲線は左端で揃えて(中心化して)あり、水準ではなく形を比べられます。下の目盛りは実際にデータがある場所を示します。それ以外ではモデルは外挿しています。

例の舞台は、k-means クラスタリングとデータサイエンスを組み合わせて製造業の廃棄削減に取り組んだ Warin、d'Anglade、de Marcellis-Warin(2025 年、International Journal of Sustainable Engineering)の研究です。データは説明のために シミュレーション したもので、論文のデータや結果では ありません。モデル比較と同じ n = 600 の生産ロットを使います。左のパネルはしきい値効果で、廃棄は低速では平らで、高速になると急に増え、曲線はどのロットでもほぼ平行です。右のパネルは前回保守からの日数で、その効果が湿度に依存するように作ってあるため、ICE 曲線は扇状に広がります。モデルは勾配ブースティング回帰で、曲線は sklearn.inspection.partial_dependence(kind="both") によります。PDP が描くのはモデルであって世界ではありません。因果的といえるのはモデルが因果的な場合だけです。

コードおよび図中のテキストは英語です。

partial-dependence.py · 56 行
ダウンロード GitHub
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.inspection import partial_dependence
# Simulated data, set in the context of Warin, d'Anglade & de Marcellis-Warin (2025) [warin2025waste]

# Data: 600 production batches; outcome = waste rate (% of material scrapped)
rng = np.random.default_rng(2025)
n = 600
names = {"speed": "Machine speed (units/min)", "temperature": "Temperature (°C)",
         "humidity": "Humidity (%)", "experience": "Operator experience (years)",
         "maintenance": "Days since maintenance", "grade": "Material grade (1 = best)",
         "batch_size": "Batch size (kg)"}
X = pd.DataFrame({"speed": rng.uniform(80, 160, n), "temperature": rng.uniform(195, 225, n),
                  "humidity": rng.uniform(30, 75, n), "experience": rng.gamma(2, 4, n),
                  "maintenance": rng.uniform(0, 120, n), "grade": rng.integers(1, 4, n),
                  "batch_size": rng.uniform(200, 1000, n)})       # batch size has no effect
y = (2 + 0.002 * np.clip(X.speed - 110, 0, None) ** 2            # waste climbs above 110 units/min
     + 0.025 * (X.temperature - 210) ** 2                        # U-shape around the 210 °C set point
     + 3 * np.exp(-X.experience / 3)                             # novices waste more, gains fade
     + 4 * (X.humidity - 30) / 45 * X.maintenance / 120          # humidity hurts worn machines most
     + 0.6 * (X.grade - 1) + rng.normal(0, 0.7, n))
model = GradientBoostingRegressor(learning_rate=0.05, n_estimators=300, max_depth=2,
                                  subsample=0.8, random_state=0).fit(X, y)

features = ["speed", "maintenance"]
change, spread = {}, {}
plt.rcParams["figure.constrained_layout.use"] = False   # manual margins leave room for the subtitle
fig, axes = plt.subplots(1, 2, figsize=(10, 5), sharey=True)
fig.subplots_adjust(left=0.10, right=0.97, top=0.80, bottom=0.12, wspace=0.08)
for ax, f in zip(axes, features):
    pd_res = partial_dependence(model, X, [f], kind="both", grid_resolution=40)
    grid = pd_res["grid_values"][0]
    ice = pd_res["individual"][0]
    ice_c = ice - ice[:, [0]]                      # centred ICE
    pdp_c = pd_res["average"][0] - pd_res["average"][0][0]
    change[f] = pdp_c[-1]                          # average effect over the whole range
    lo, hi = np.percentile(ice_c, [10, 90], axis=0)
    spread[f] = (lo[-1], hi[-1])
    ax.plot(grid, ice_c.T, color="#007AFF", alpha=0.07, lw=0.8)
    ax.plot(grid, pdp_c, color="#FF9500", lw=3, label="Average (PDP)")
    ax.plot(grid, lo, color="#007AFF", lw=1, ls="--")
    ax.plot(grid, hi, color="#007AFF", lw=1, ls="--", label="10th / 90th percentile of ICE")
    ax.plot(X[f], np.full(len(X), -1.3), "|", color="#3A3A3C", ms=8, alpha=0.4)   # rug
    ax.set_xlabel(names[f])
    ax.set_title(f"Effect of {names[f].split(' (')[0].lower()}")
axes[0].set_ylim(-1.6, 6.5)
axes[0].set_ylabel("Change in predicted waste rate\n(points, relative to the lowest value)")
axes[0].legend(loc="upper left", fontsize=9)
m_lo, m_hi = spread["maintenance"]
fig.suptitle(f"Speed adds {change['speed']:.1f} points of waste for every batch; {grid[-1]:.0f} days without "
             f"maintenance add {m_lo:.1f} to {m_hi:.1f}", x=0.02, y=0.97, ha="left")
fig.text(0.02, 0.885, f"Gradient boosting · n = {n} batches (simulated) · thin lines = one batch (centred ICE) · "
         "ticks = observed values", fontsize=9.5, color="#6E6E73")
plt.show()

図にはオプションの PyStatlas スタイル を使用しています。同じ見た目にするには plt.style.use("pystatlas.mplstyle") を追加してください。

データの出典

  • Simulated data. Simulated data with a fixed random seed, created for this example.
    No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work.
  • Warin, d'Anglade & de Marcellis-Warin (2025), data science for waste reduction in manufacturing. Warin, T., d'Anglade, P. M., & de Marcellis-Warin, N. (2025). Optimising industrial efficiency: Integrating K-means clustering and data science for sustainable manufacturing and waste reduction. International Journal of Sustainable Engineering, 18(1), 2527300. https://doi.org/10.1080/19397038.2025.2527300
    The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.

これらの例は統計手法を説明するためのものです。項目に別の記載がない限り数値はシミュレーションであり、図のタイトルはこのシミュレーションデータで図が示す内容を述べたものです。引用した論文の知見でも、実質的な問いに対する著者の立場でもありません。結果、背景、データについては、ここに挙げた論文を参照してください。

引用方法

PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。

Warin, T. (2026). Partial dependence with ICE curves. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/machine-learning/partial-dependence/

@misc{warin2026statlas,
  author       = {Warin, Thierry},
  title        = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
  year         = {2026},
  version      = {1.1.0},
  howpublished = {\url{https://warin.ca/pystatlas/}},
  note         = {Source code: https://github.com/warint/pystatlas}
}

機械学習のその他のグラフ