Model Interpretability
Model Interpretability
The property of making an AI model's decision process understandable.
Model Interpretability
The property of making an AI model's decision process understandable.
Model Interpretability is the ability to explain, in a way humans can understand, how an AI system arrived at a particular conclusion. It is essential for building trustworthy AI systems, regulatory compliance, and model debugging, and is a core concept of Explainable AI (XAI).
Interpretability is divided into two dimensions: 1) Intrinsic interpretability - models whose structure itself is interpretable, such as linear regression and decision trees, 2) Post-hoc interpretability - methods of explaining complex black-box models with separate techniques. There is generally a trade-off between the high performance of deep learning and interpretability.
Major interpretation techniques include SHAP (Shapley Additive Explanations), LIME (Local Interpretable Model-agnostic Explanations), Grad-CAM (images), and Attention Visualization (NLP). SHAP fairly distributes the contribution of each feature based on game theory, while LIME generates explanations locally with a simple surrogate model.
In high-risk domains such as finance, healthcare, and law, regulations such as the GDPR's "right to explanation" and Korea's Credit Information Act require interpretability. Beyond merely technical explanations, generating user-friendly explanations that non-experts can also understand is becoming increasingly important.
This is a model interpretation example using SHAP and LIME:
import shap
import lime
import lime.lime_tabular
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
# 데이터 및 모델 준비
data = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(
data.data, data.target, test_size=0.2, random_state=42
)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
# 1. SHAP 분석
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)
# 전역적 피처 중요도 (평균 절대 SHAP 값)
feature_importance = np.abs(shap_values[1]).mean(axis=0)
top_features = sorted(zip(data.feature_names, feature_importance),
key=lambda x: x[1], reverse=True)[:5]
print("=== SHAP 전역 피처 중요도 (Top 5) ===")
for name, importance in top_features:
print(f" {name}: {importance:.4f}")
# 개별 예측 설명
sample_idx = 0
print(f"\n=== 샘플 {sample_idx} 개별 설명 ===")
print(f"예측: {'악성' if model.predict([X_test[sample_idx]])[0] == 0 else '양성'}")
sample_shap = shap_values[1][sample_idx]
top_contributors = sorted(zip(data.feature_names, sample_shap),
key=lambda x: abs(x[1]), reverse=True)[:3]
for name, value in top_contributors:
direction = "증가" if value > 0 else "감소"
print(f" {name}: 양성 확률 {direction} ({value:+.4f})")
# 2. LIME 분석
lime_explainer = lime.lime_tabular.LimeTabularExplainer(
X_train,
feature_names=data.feature_names,
class_names=['악성', '양성'],
mode='classification'
)
# 개별 예측에 대한 LIME 설명
lime_exp = lime_explainer.explain_instance(
X_test[sample_idx],
model.predict_proba,
num_features=5
)
print(f"\n=== LIME 로컬 설명 (샘플 {sample_idx}) ===")
for feature, weight in lime_exp.as_list():
print(f" {feature}: {weight:+.4f}")
# 3. 피처 중요도 비교 (SHAP vs 기본 중요도)
print("\n=== 피처 중요도 비교 ===")
print(f"{'피처':<30} {'RF 중요도':<12} {'SHAP 중요도':<12}")
print("-" * 54)
for i in np.argsort(model.feature_importances_)[-5:][::-1]:
print(f"{data.feature_names[i]:<30} "
f"{model.feature_importances_[i]:.4f} "
f"{feature_importance[i]:.4f}")| Interpretation Technique | Computational Cost | Applicable Models | Interpretation Scope |
|---|---|---|---|
| Feature Importance | Low | Tree-based | Global |
| SHAP (TreeExplainer) | Medium | Tree-based | Global + Local |
| SHAP (KernelExplainer) | High | All models | Global + Local |
| LIME | Medium | All models | Local |
| Grad-CAM | Low | CNN | Local (visualization) |
"For this rejected case, we can tell the customer the top 3 main reasons for rejection using SHAP values."
Used when planning an explanation feature for AI decisions.
"We have to submit a model interpretability report to the Financial Services Commission, so I included a SHAP summary plot and a feature importance analysis."
Used when providing documented interpretation results in response to regulators.
"I checked with Grad-CAM, and the model is looking at strange places. It seems there's data bias."
An expression used when debugging model problems with interpretation tools.
1. Overconfidence in interpretation results: SHAP/LIME are approximations and not perfect explanations. Interpretations can be unstable, especially when correlations between features are high.
2. Confusing global vs. local: Even if global feature importance is high, other features may be decisive in an individual prediction. Choose the level of interpretation that fits your purpose.
3. Lack of explanations for non-experts: SHAP values themselves are hard for general users to understand. Convert them into natural language, such as "Rejected because income is lower than average."
4. Ignoring the interpretability–accuracy trade-off: Always using an interpretable model can reduce performance. Strike a balance that fits domain requirements.