I am new to MLR3 and I am loving it! Great job there! Lennart Schneider provides a very nice example of Regression chains https://mlr3gallery.mlr-org.com/posts/2020-04-18-regression-chains/ That got me thinking - how can I implement this using mixed types of output. Suppose for example (adapted from his example):
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 is clear and remains the same (directly copied from the example):
#-- 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]]
How does the rest of the pipeline proceeds when Y2 is a class output (step 2 is a classification step) and Step 3 is survival data (Step 3 is survival step).
I can provide more information if you like.
Many thanks in advance