我有一个关于在进行嵌套重采样时提取预测的简单问题。我不知道如何在数据表中提取验证集和测试集的结果:
这是我的代码:
set.seed(1234)
rr_xgboost = tune_nested(tuner = tnr("mbo"), task = task_imp12, learner = learner_xgboost, inner_resampling = resampling_inner, outer_resampling = resampling_outer, measure = msr("classif.auc"), term_evals = 10, store_models = TRUE, terminator = trm("none"))
xgboost_results_validation <- extract_inner_tuning_results(rr_xgboost)[, .SD, .SDcols = !c("learner_param_vals", "x_domain")]
AUC_validation = xgboost_results_validation$classif.auc
AUC_test = rr_xgboost$score(msr("classif.auc"))
predictions <- rr_xgboost$predictions()
View(predictions)
predictions
[[1]]
<PredictionClassif> for 234 observations:
row_ids truth response prob.0 prob.1
7 0 0 0.5522561 0.4477439
8 0 0 0.6626639 0.3373361
9 0 0 0.5247233 0.4752767
---
1025 0 0 0.8272567 0.1727433
1026 0 0 0.6095791 0.3904209
1027 1 0 0.7445868 0.2554132
感谢马克:
Predictions_validation_xgboost <-irr$resample_result[[1]]$predictions()[[1]]
Predictions_test_xgboost <- predictions$prediction[[1]]
Predictions_validation_xgboost <- as.data.table(Predictions_validation_xgboost)
Predictions_test_xgboost <- as.data.table(Predictions_test_xgboost)
下次请发布一个可重现的示例。
library(mlr3verse)
tsk_sonar = tsk("sonar")
tnr_grid_search = tnr("grid_search", resolution = 5, batch_size = 5)
lrn_svm = lrn("classif.svm",
cost = to_tune(1e-5, 1e5, logscale = TRUE),
gamma = to_tune(1e-5, 1e5, logscale = TRUE),
kernel = "radial",
type = "C-classification"
)
rsmp_cv3 = rsmp("cv", folds = 3)
msr_ce = msr("classif.ce")
at = auto_tuner(
tuner = tnr_grid_search,
learner = lrn_svm,
resampling = rsmp("cv", folds = 4),
measure = msr_ce,
)
rr = resample(tsk_sonar, at, rsmp_cv3, store_models = TRUE)
rr
irr = extract_inner_tuning_archives(rr)
包含内循环的所有重采样结果/预测。您可以使用 irr$resample_result[[1]]$predictions()
访问第一个。 rr$predictions()
包含外循环的预测。