我有一个基因数据集,其引起疾病的可能性得分在 0 到 1 之间(已知得分为 1 的基因会引起疾病,得分为 0.74 的基因可能会引起疾病)。我正在尝试建立一个机器学习模型来预测回归分类中新基因的疾病评分。
我想查看已知疾病基因但得分较低的基因的形状决策图(例如,得分为 1 的基因,但我的模型得分低于 0.8)。我正在努力将这些基因组合在一起进行绘图。
我的数据如下所示:
X:
Index Feature1 Feature2 ... FeatureN
Gene1 1 0.2 10
Gene2 1 0.1 7
Gene3 0 0.3 10
#index is actually the index and not a column
Y:
Score
1
0.6
0.4
我运行带有嵌套交叉验证的 xgboost 回归器,查看 MSE、预测的 r2,并绘制观察值与预期值的关系图。我可以在观察到的与预期的图中看到,Y 中得分为 1 的基因有许多模型预测的低分,我想了解为什么模型使用 shap 来做到这一点。不幸的是,我无法提供示例数据。
我正在尝试调整为标签分类给出的示例 shap 代码:
import shap
xgbr = xgboost.XGBRegressor()
xgbr.fit(X_train, Y_train)
select = range(8) #I have 8 features after feature selection with BorutaShap
features = X.iloc[select]
features_display = X.loc[features.index]
explainer = shap.TreeExplainer(xgbr)
expected_value = explainer.expected_value
#Example code from https://slundberg.github.io/shap/notebooks/plots/decision_plot.html:
y_pred = xgbr.predict(X)
y_pred = (shap_values.sum(1) + expected_value) > 0
misclassified = y_pred != y_test[select]
shap.decision_plot(expected_value, shap_values, features_display, link='logit', highlight=misclassified)
我该如何选择,y_pred以便预测/基因本应为 1,但实际上低于 0.8(或任何低数字)?
编辑:为了回应给定的答案,我尝试过:
explainer = shap.TreeExplainer(xgbr)
shap_values = explainer.shap_values(X_test)
y_pred = xgbr.predict(X_test)
m = (y_pred <= 0.5) & (Y_test == 1)
shap.initjs()
shap.decision_plot(explainer.expected_value, shap_values, X_test[m], return_objects=True)
它运行但m长度为 171(我的 Y_test 数据中的全部行数),然后该图绘制了它看起来像的所有 171 - 而且我从查看数据知道应该只有一个基因 <= 0.5 并且但实际上得分为 1。
慕尼黑5688855
拉莫斯之舞
相关分类