h2o SHAP 值 / predict_contributions 用于交叉验证
h2o SHAP values / predict_contributions for cross validation
我研究了 h2o.predict_contributions 函数,该函数公开了 xgb 和 gbm 模型的 Shap 值。此功能是否也提供来自交叉验证预测的这些指标?我好像找不到。
library(h2o)
library(mlbench)
data(Sonar)
Sonar.h2o = as.h2o(Sonar)
mdl = h2o.xgboost(x=names(Sonar), y='Class', training_frame = Sonar, nfolds=5, keep_cross_validation_predictions = TRUE)
是的,您可以将函数应用于感兴趣的单折,这里是一些示例代码:
library(h2o)
h2o.init()
prostate_path <- system.file("extdata", "prostate.csv", package = "h2o")
prostate <- h2o.uploadFile(path = prostate_path)
prostate_gbm <- h2o.gbm(3:9, "AGE", prostate, nfolds = 3)
h2o.predict(prostate_gbm, prostate)
h2o.predict_contributions(prostate_gbm, prostate)
# take a look at the output to see which key you want to use
# there are also other options to key names
prostate_gbm@model$cross_validation_models
# update this with the key of interest
key = 'GBM_model_R_1557326910287_7702_cv_2'
cv2 = h2o.getModel(key)
h2o.predict_contributions(cv2, prostate)
# RACE DPROS DCAPS PSA VOL GLEASON __internal_cv_weights__ BiasTerm
# 1 -0.006481315 -0.19211742 -0.0836791 -0.06186131 -0.9217098 -0.20128664 0 66.37209
# 2 -0.005238285 -1.09128833 0.9614767 -0.95340544 -0.7698430 0.06820074 0 66.37209
# 3 -0.006481315 0.98101193 0.1770813 1.21195042 -1.0359415 -0.23213011 0 66.37209
# 4 0.069538474 -0.01738315 -0.2000238 4.11799049 0.1177490 -0.01457024 0 66.37209
# 5 0.012923095 0.40362182 -0.1132747 1.21669090 0.9920316 -0.37245926 0 66.37209
# 6 -0.002282504 -0.91798097 0.9024866 -0.17398398 -0.6048008 0.42300656 0 66.37209
注意:您可以忽略 __internal_cv_weights__
列。我已经创建了一张票来清理可以跟踪的输出 here.
我研究了 h2o.predict_contributions 函数,该函数公开了 xgb 和 gbm 模型的 Shap 值。此功能是否也提供来自交叉验证预测的这些指标?我好像找不到。
library(h2o)
library(mlbench)
data(Sonar)
Sonar.h2o = as.h2o(Sonar)
mdl = h2o.xgboost(x=names(Sonar), y='Class', training_frame = Sonar, nfolds=5, keep_cross_validation_predictions = TRUE)
是的,您可以将函数应用于感兴趣的单折,这里是一些示例代码:
library(h2o)
h2o.init()
prostate_path <- system.file("extdata", "prostate.csv", package = "h2o")
prostate <- h2o.uploadFile(path = prostate_path)
prostate_gbm <- h2o.gbm(3:9, "AGE", prostate, nfolds = 3)
h2o.predict(prostate_gbm, prostate)
h2o.predict_contributions(prostate_gbm, prostate)
# take a look at the output to see which key you want to use
# there are also other options to key names
prostate_gbm@model$cross_validation_models
# update this with the key of interest
key = 'GBM_model_R_1557326910287_7702_cv_2'
cv2 = h2o.getModel(key)
h2o.predict_contributions(cv2, prostate)
# RACE DPROS DCAPS PSA VOL GLEASON __internal_cv_weights__ BiasTerm
# 1 -0.006481315 -0.19211742 -0.0836791 -0.06186131 -0.9217098 -0.20128664 0 66.37209
# 2 -0.005238285 -1.09128833 0.9614767 -0.95340544 -0.7698430 0.06820074 0 66.37209
# 3 -0.006481315 0.98101193 0.1770813 1.21195042 -1.0359415 -0.23213011 0 66.37209
# 4 0.069538474 -0.01738315 -0.2000238 4.11799049 0.1177490 -0.01457024 0 66.37209
# 5 0.012923095 0.40362182 -0.1132747 1.21669090 0.9920316 -0.37245926 0 66.37209
# 6 -0.002282504 -0.91798097 0.9024866 -0.17398398 -0.6048008 0.42300656 0 66.37209
注意:您可以忽略 __internal_cv_weights__
列。我已经创建了一张票来清理可以跟踪的输出 here.