获取使用 kNN 进行的预测的 SHAP 值

  • 本文关键字:SHAP kNN 获取 shap
  • 更新时间 :
  • 英文 :


如果我想为具有 n 个变量的 kNN 分类器获取带有内核 SHAP 的 SHAP 值,我是否必须重新计算预测 2^n 次?

(我使用的不是python,而是MATLAB,所以我需要知道算法的内部(

对于那些使用python的人,可以找到以下脚本从knn模型中获取shap值。有关分步建模,请点击此链接:

# Initialize model
knn = sklearn.neighbors.KNeighborsClassifier()
# Fit the model
knn.fit(X_train, Y_train)
# Get the model explainer object
explainer = shap.KernelExplainer(knn.predict_proba, X_train)
# Get shap values for the test data observation whose index is 0, i.e. first observation in the test set
shap_values = explainer.shap_values(X_test.iloc[0,:])
# Generate a force plot for this first observation using the derived shap values
shap.force_plot(explainer.expected_value[0], shap_values[0], X_test.iloc[0,:])

是的,根据题为"解释模型的统一方法"的论文,我相信是这样 预测'。

您将需要遍历所有特征联盟:因此是 2^n(其中特征数为 n(。