1

我是 MLR3 的新手,我很喜欢它!那里做得很好!Lennart Schneider 提供了一个非常好的回归链示例https://mlr3gallery.mlr-org.com/posts/2020-04-18-regression-chains/ 这让我开始思考——如何使用混合类型的输出来实现它。假设例如(改编自他的例子):

library(data.table)
library(mvtnorm)
set.seed(2409)
n = 100
(mean = c(y1 = 1, y2 = 2, y3 = 3))
(sigma = matrix(c(1, -0.5, 0.25, -0.5, 1, -0.25, 0.25, -0.25, 1),
  nrow = 3, ncol = 3, byrow = TRUE))
Y = rmvnorm(n, mean = mean, sigma = sigma)
Y[,2] = 1.*(Y[,2]> 2)
Y[,3] = mapply(rexp, n=1, rate = 1/exp(Y[,3]-1.))
status = 1.*(Y[,3] > 4) (right censoring indicator)
dat = as.data.table(cbind(Y,status, x1, x2))
str(dat)

Step1 很清楚并且保持不变(直接从示例中复制):

#-- Building Pipeline
library(mlr3)
library(mlr3learners)
library(mlr3pipelines)
library(mlr3misc)
#library(mlr)
task = TaskRegr$new("multiregression", backend = dat, target = "y1") ## Define the Task 1

#Use the input to predict y1 within the first learner (i.e., y1∼x1+x2).
step1 = po("copy", outnum = 2, id = "copy1") %>>%
  gunion(list(
    po("colroles", id = "drop_y2_y3",
       param_vals = list(new_role = list(y2 = character(), y3 = character()))) %>>% ## this line here drops the varaibles
      po("learner_cv", learner = lrn("regr.lm"), id = "y1_learner"), # we push this to a regr. learner
    po("nop", id = "nop1")
  )) %>>%
  po("featureunion", id = "union1")
step1$plot()
step1$train(task)[[1]]

当 Y2 是类输出(步骤 2 是分类步骤)且步骤 3 是生存数据(步骤 3 是生存步骤)时,管道的其余部分如何进行。

如果您愿意,我可以提供更多信息。

提前谢谢了

4

0 回答 0