Files
nexus/wiki/concepts/Partial-Dependence-Plots.md

72 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Partial Dependence Plots"
type: concept
tags: [model-interpretability, feature-analysis, model-visualization]
last_updated: 2026-04-25
---
## Definition
偏依赖图Partial Dependence PlotsPDP展示一个或两个特征与模型预测之间的边际关系——在控制其他特征后该特征取不同值时模型输出的平均预测变化。核心假设特征之间相对独立独立PDP否则需要 ICE 曲线Individual Conditional Expectation补充。
## Core Types
### 1D PDP单特征
- 固定其他特征不动,在目标特征的取值范围内计算模型平均预测
- 可视化x 轴为特征值y 轴为偏依赖值(边际预测效应)
- 用于:验证特征方向是否符合业务预期(单调递增/递减/U形
### 2D PDP特征交互
- 两个特征同时变化,展示交互效应对预测的联合影响
- 用于:检测模型学习到的非预期特征交互(如 X₁ × X₂ 的非线性组合)
### ICE CurvesIndividual Conditional Expectation
- 每条线代表一个样本的偏依赖曲线(而非平均值)
- 解决 PDP 掩盖个体异质性的问题
- 与 PDP 结合PDP 叠加 ICE 曲线,同时展示平均趋势和个体差异
## Usage
```python
from sklearn.inspection import PartialDependenceDisplay
# 1D PDP for single feature
fig, ax = plt.subplots(figsize=(8, 5))
PartialDependenceDisplay.from_estimator(
model, X, [feature_name],
grid_resolution=50, ax=ax
)
ax.set_title(f"Partial Dependence - {feature_name}")
fig.savefig(f"pdp_{feature_name}.png", dpi=150)
# 2D PDP for feature interaction
fig, ax = plt.subplots(figsize=(8, 6))
PartialDependenceDisplay.from_estimator(
model, X, [(feat_a, feat_b)], ax=ax
)
fig.savefig(f"pdp_interact_{feat_a}_x_{feat_b}.png", dpi=150)
```
## Model QA 中的应用
Model QA Specialist 使用 PDP 进行以下审计:
1. **方向性验证**:检查 PDP 曲线方向是否符合业务领域知识(如"收入↑ → 违约概率↓"
2. **非单调性检测**:识别模型在某些区间学习到的反直觉非单调关系
3. **交互效应识别**2D PDP 检测 top correlated feature pairs 的交互效应
4. **跨时间稳定性**:对比 Train vs OOT 的 PDP 曲线,识别特征关系的时间漂移
5. **SHAP 交叉验证**PDP 验证边际方向SHAP 验证精确归因,两者互补
## Relationship
- **依赖** [[SHAP]]SHAP 提供精确特征归因PDP 提供趋势可视化PDP 曲线形状与 SHAP beeswarm 的分布吻合
- **依赖** [[Population-Stability-Index]]PSI 捕捉特征分布漂移PDP 捕捉特征效应的变化,两者共同判断模型是否需要重训
- **支撑** [[Calibration-Testing]]PDP 揭示的非线性关系可能是校准问题的根源
- **支撑** [[specialized-model-qa]]SourceModel QA Specialist 的特征分析核心工具
## Key Limitations
- **强交互效应**当特征高度相关时PDP 可能产生误导性结论(忽略其他特征的条件分布)
- **异质性掩盖**:个体 ICE 曲线与平均 PDP 的差异反映异质性,忽略可能遗漏关键子群体
- **分类变量**:需预先分箱,箱的划分方式影响结果解释
- **高维特征**:超过 2 个特征的交互需用 SHAP interaction values 或 ALE plots