用 LIME 评估忠实度
已为收入数据集中的一个样本 X_instance 提供了 LIME 解释。鉴于性别是最重要的预测因子,您需要修改其取值并计算 faithfulness,以判断该解释与该样本上模型行为的一致程度。
本练习是课程的一部分
Python 可解释性 AI
练习说明
- 将
X_instance中的性别取值改为 0。 - 生成一个
new_prediction概率。 - 估计 LIME 解释的
faithfulness。
交互式实操练习
通过完成这段示例代码来试试这个练习。
original_prediction = model.predict_proba(X_instance)[0, 1]
print(f"Original prediction: {original_prediction}")
# Change the gender value to 0
____
# Generate the new prediction
new_prediction = ____
print(f"Prediction after perturbing 'gender': {new_prediction}")
# Estimate faithfulness
faithfulness_score = ____
print(f"Local Faithfulness Score: {faithfulness_score}")