我正在按照说明进行操作(https://mlr.mlr-org.com/articles/tutorial/create_learner.html)创建用于MLR的参数生存学习器。我的代码在下面。
当我试图使MakeLearner(id="AFT","surv.parameter"(时,我得到了一个错误dist丢失并且没有设置默认值,即使我已经在代码中指定dist默认值为";weibull";。
makeRLearner.surv.parametric = function() {
makeRLearnerSurv(
cl = "surv.parametric",
package = "survival",
par.set = makeParamSet(
makeDiscreteLearnerParam(id = "dist", default = "weibull",
values = c("weibull", "exponential", "lognormal", "loglogistic")),
),
properties = c("numerics", "factors", "weights", "prob", "rcens"),
name = "Parametric Survival Model",
short.name = "Parametric",
note = "This is created based on MLR3 surv.parametric learner"
)
}
trainLearner.surv.parametric = function (.learner, .task, .subset, .weights = NULL, ...)
{
f = getTaskFormula(.task)
data = getTaskData(.task, subset = .subset)
if (is.null(.weights)) {
mod = survival::survreg(formula = f, data = data, ...)
}
else {
mod = survival::survreg(formula = f, data = data, weights = .weights, ...)
}
mod
}
predictLearner.surv.parametric = function (.learner, .model, .newdata, ...)
{
survival::predict.survreg(.model$learner.model, newdata = .newdata, type = "response", ...)
}
基于此,预测函数需要返回线性预测因子,这将是lp
而不是response
。此外,MLR的cindex
函数似乎与SurvReg
的输出不一致。基于这个讨论,加一个减号似乎可以解决这个问题。因此,预测函数如下。
predictLearner.surv.reg = function(.learner, .model, .newdata, ...) {
-predict(.model$learner.model, newdata = .newdata, type = "lp", ...)
}