mlr:测试 FailureModel 的最佳方法是什么?

mlr: What is the best way to test for a FailureModel?

mlr 函数 configureMlr() 允许用户设置以下参数:

on.learner.error: What should happen if an error in an underlying learning algorithm is caught “warn”: A FailureModel will be created, which predicts only NAs and a warning will be generated.

检查是否已返回 FailureModel 的最佳方法是什么?目前我只是检查模型的 class,如果它不是应该的,那么我假设它是一个 FailureModel。

library(survival)
library(mlr)
library(mlrCPO)

data(veteran)
set.seed(24601)
task_id = "MAS"
mas.task <- makeSurvTask(id = task_id, data = veteran, target = c("time", "status"))
mas.task <- createDummyFeatures(mas.task)

preproc_pipeline <- cpoScale()  # Standardise the numerical data - center and scale
outer = makeResampleDesc("CV", iters=5, stratify=TRUE)  # Benchmarking

cox.lrn <- preproc_pipeline %>>% makeLearner(cl="surv.coxph", id = "coxph", predict.type="response")
learners = list( cox.lrn )  
bmr = benchmark(learners=learners, tasks=mas.task, resamplings=outer, measures=list(cindex), show.info = TRUE, models=TRUE)

model_id = 'coxph.scale'
mods = getBMRModels(bmr, learner.ids = c(model_id))
num_models = length(mods[[task_id]][[model_id]])

for (i in 1:num_models) {
  mod = getLearnerModel(mods[[task_id]][[model_id]][[i]], more.unwrap=TRUE)
  if (class(mod) == "coxph") {
    print(mod$coefficients)
  } else {
    print("Failure model")
  }
}

我尝试了以下方法,

  if (isFailureModel(mod)) {
    print("FailureModel")
  }

但收到错误消息:

Error in UseMethod("isFailureModel") : 
  no applicable method for 'isFailureModel' applied to an object of class "coxph"

我不认为有一个简单的解决方案(至少我不知道)。

您的方法似乎离成功不远了。但是,如?mlr::isFailureModel()中所述,它需要应用于classWrapperModel的对象,而不是特定模型class的对象(例如coxph in你的情况)。