knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(mlr3)
library(mlr3pipelines)
library(mlr3multioutput)

mlr3multioutput

Storing and working with multi-output Tasks in mlr3.

Multi-output Tasks are tasks with multiple targets of possibly different task_types that share the same features (and therefore observations).

Scope

The packages scope is currently to ...

General API

Task

t = tsk("linnerud")
t

Learner

l = lrn("multioutput.featureless")
l

Train & Predict

l$train(t)
p = l$predict(t)
p

Score

p$score()

Measure

Current limitations: - One one predict_type: "response" - One of minimize, weights etc. - score() output has to be a scalar.

m1 = msr(
  "multioutput.custom",
  measures = list("regr" = msr("regr.mse")),
  weights =  c(Pulls = 1, Squats = 0.3, Jumps = 2)
)
m1
p$score(m1)

with mlr3pipelines

po("multioutsplit")$train(list(t))
po("multioutunite") # See example below.
po("multioutlrn", learners = list(lrn("regr.rpart"), lrn("classif.rpart")))

Approach 1: Multiplicity (same learner for all targets)

gr = po("multioutsplit") %>>%
 lrn("regr.rpart") %>>%
 po("multioutunite")
gr = GraphLearner$new(gr)

gr$train(t)
gr$predict(t)

Approach 2: Multiplicity (per-task-type)

API:

gr = po("multioutsplit") %>>%
 po("multioutlrn", learners = list(regr = lrn("regr.rpart"), classif = lrn("classif.rpart")))

gl = GraphLearner$new(gr)
gl$train(t)
prds = gl$predict(t)
prds

Unclear: - What does the ParamSet look like? Just unite and prefix with id?

Approach 3: Multiplicity (per-target)

Current problems: - How to map learners to targets? - Names are lost through multiplicitlyimply

Internals

gr = po("multioutsplit") %>>%
  po("multiplicityexply", outnum = 3) %>>%
  gunion(list(
    lrn("regr.rpart", id = "rp1"),
    lrn("regr.rpart", id = "rp2"),
    lrn("regr.rpart", id = "rp3")
 )) %>>%
 po("multiplicityimply", innum = t$target_names) %>>%
 po("multioutunite")

gl = GraphLearner$new(gr)
gl$train(t)
prds = gl$predict(t)
prds

with mlr3keras

Not implemented

library(mlr3keras)
lrn("multioutput.kerasff")

Example Pipeline

library(mlr3)
library(mlr3pipelines)
library(mlr3tuning)
library(paradox)

task = tsk("linnerud")

gr = PipeOpSplitMultiout$new() %>>% lrn("regr.rpart") %>>% PipeOpPredictionMultiOutUnite$new()

grl = GraphLearner$new(gr)

ps = ParamSet$new(
  list(
    ParamInt$new("regr.rpart.minsplit", lower = 1, upper = 10),
    ParamInt$new("regr.rpart.maxdepth", lower = 1, upper = 3)
  )
)

cv3 = rsmp("cv", folds = 3)

ms = MeasureMultioutputWeightedAvg$new(measures = list(
  "regr" = msr("regr.mse")
))

auto = AutoTuner$new(
  learner = grl,
  resampling = cv3,
  measure = ms,
  search_space = ps,
  terminator = trm("evals", n_evals = 5),
  tuner = tnr("random_search")
)

auto$train(task)


mlr-org/mlr3multioutput documentation built on Nov. 22, 2020, 1:17 p.m.