Create a new Graph
for a classification Task to
perform "One vs. Rest" classification.
All input arguments are cloned and have no references in common with the returned Graph
.
Arguments
- graph
Graph
Graph being wrapped betweenPipeOpOVRSplit
andPipeOpOVRUnite
. The Graph should returnNULL
during training and a classification Prediction during prediction.
Examples
library("mlr3")
task = tsk("wine")
learner = lrn("classif.rpart")
learner$predict_type = "prob"
# Simple OVR
g1 = pipeline_ovr(learner)
g1$train(task)
#> $ovrunite.output
#> NULL
#>
g1$predict(task)
#> $ovrunite.output
#> <PredictionClassif> for 178 observations:
#> row_ids truth response prob.1 prob.2 prob.3
#> 1 1 1 0.93301153 0.04437722 0.02261125
#> 2 1 1 0.93301153 0.04437722 0.02261125
#> 3 1 1 0.93301153 0.04437722 0.02261125
#> ---
#> 176 3 3 0.08896784 0.04157376 0.86945841
#> 177 3 3 0.08896784 0.04157376 0.86945841
#> 178 3 3 0.01729144 0.04484461 0.93786395
#>
# Bagged Learners
gr = po("replicate", reps = 3) %>>%
po("subsample") %>>%
learner %>>%
po("classifavg", collect_multiplicity = TRUE)
g2 = pipeline_ovr(gr)
g2$train(task)
#> $ovrunite.output
#> NULL
#>
g2$predict(task)
#> $ovrunite.output
#> <PredictionClassif> for 178 observations:
#> row_ids truth response prob.1 prob.2 prob.3
#> 1 1 1 0.93801099 0.05417103 0.00781798
#> 2 1 1 0.93801099 0.05417103 0.00781798
#> 3 1 1 0.93801099 0.05417103 0.00781798
#> ---
#> 176 3 3 0.21422882 0.04551151 0.74025967
#> 177 3 3 0.21422882 0.04551151 0.74025967
#> 178 3 3 0.03695298 0.05577925 0.90726778
#>
# Bagging outside OVR
g3 = po("replicate", reps = 3) %>>%
pipeline_ovr(po("subsample") %>>% learner) %>>%
po("classifavg", collect_multiplicity = TRUE)
g3$train(task)
#> $classifavg.output
#> NULL
#>
g3$predict(task)
#> $classifavg.output
#> <PredictionClassif> for 178 observations:
#> row_ids truth response prob.1 prob.2 prob.3
#> 1 1 1 0.94066508 0.05111255 0.008222368
#> 2 1 1 0.94066508 0.05111255 0.008222368
#> 3 1 1 0.94066508 0.05111255 0.008222368
#> ---
#> 176 3 3 0.11028161 0.04653909 0.843179301
#> 177 3 3 0.11028161 0.04653909 0.843179301
#> 178 3 3 0.03724958 0.05160886 0.911141558
#>