開始使用免費開始

評估 SHAP 解釋的一致性

使用 SHAP 值,評估保險資料集兩個不同子集之間的特徵重要性解釋是否一致。

已為你預先載入子集 X1X2y1y2,並提供在第一個子集上訓練的 model1 與在第二個子集上訓練的 model2

本練習屬於課程

Python 的 Explainable AI

檢視課程

練習說明

  • 計算 model1shap_values1feature_importance1
  • 計算 model2shap_values2feature_importance2
  • 計算特徵重要性之間的 consistency

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Calculate SHAP values and feature importance for model1
explainer1 = shap.TreeExplainer(model1)
shap_values1 = ____
feature_importance1 = ____

# Calculate SHAP values and feature importance for model2
explainer2 = shap.TreeExplainer(model2)
shap_values2 = ___
feature_importance2 =____

# Consistency calculation
consistency = ____
print("Consistency between SHAP values:", consistency)
編輯並執行程式碼