14  The Building Blocks: PipeOps

The building blocks of mlr3pipelines are PipeOp-objects (PO). They can be constructed directly using PipeOp<NAME>$new(), but the recommended way is to retrieve them from the mlr_pipeops dictionary:

                      key                         packages
 1:                boxcox      mlr3pipelines,bestNormalize
 2:                branch                    mlr3pipelines
 3:                 chunk                    mlr3pipelines
 4:        classbalancing                    mlr3pipelines
 5:            classifavg              mlr3pipelines,stats
 6:          classweights                    mlr3pipelines
 7:              colapply                    mlr3pipelines
 8:       collapsefactors                    mlr3pipelines
 9:              colroles                    mlr3pipelines
10:                  copy                    mlr3pipelines
11:          datefeatures                    mlr3pipelines
12:                encode              mlr3pipelines,stats
13:          encodeimpact                    mlr3pipelines
14:            encodelmer        mlr3pipelines,lme4,nloptr
15:          featureunion                    mlr3pipelines
16:                filter                    mlr3pipelines
17:            fixfactors                    mlr3pipelines
18:               histbin           mlr3pipelines,graphics
19:                   ica            mlr3pipelines,fastICA
20:        imputeconstant                    mlr3pipelines
21:            imputehist           mlr3pipelines,graphics
22:         imputelearner                    mlr3pipelines
23:            imputemean                    mlr3pipelines
24:          imputemedian              mlr3pipelines,stats
25:            imputemode                    mlr3pipelines
26:             imputeoor                    mlr3pipelines
27:          imputesample                    mlr3pipelines
28:             kernelpca            mlr3pipelines,kernlab
29:               learner                    mlr3pipelines
30:            learner_cv                    mlr3pipelines
31:               missind                    mlr3pipelines
32:           modelmatrix              mlr3pipelines,stats
33:     multiplicityexply                    mlr3pipelines
34:     multiplicityimply                    mlr3pipelines
35:                mutate                    mlr3pipelines
36:                   nmf           mlr3pipelines,MASS,NMF
37:                   nop                    mlr3pipelines
38:              ovrsplit                    mlr3pipelines
39:              ovrunite                    mlr3pipelines
40:                   pca                    mlr3pipelines
41:                 proxy                    mlr3pipelines
42:           quantilebin              mlr3pipelines,stats
43:      randomprojection                    mlr3pipelines
44:        randomresponse                    mlr3pipelines
45:               regravg                    mlr3pipelines
46:       removeconstants                    mlr3pipelines
47:         renamecolumns                    mlr3pipelines
48:             replicate                    mlr3pipelines
49:                 scale                    mlr3pipelines
50:           scalemaxabs                    mlr3pipelines
51:            scalerange                    mlr3pipelines
52:                select                    mlr3pipelines
53:                 smote        mlr3pipelines,smotefamily
54:           spatialsign                    mlr3pipelines
55:             subsample                    mlr3pipelines
56:          targetinvert                    mlr3pipelines
57:          targetmutate                    mlr3pipelines
58: targettrafoscalerange                    mlr3pipelines
59:        textvectorizer mlr3pipelines,quanteda,stopwords
60:             threshold                    mlr3pipelines
61:         tunethreshold              mlr3pipelines,bbotk
62:              unbranch                    mlr3pipelines
63:                vtreat             mlr3pipelines,vtreat
64:            yeojohnson      mlr3pipelines,bestNormalize
                      key                         packages
                                tags
 1:                   data transform
 2:                             meta
 3:                             meta
 4:   imbalanced data,data transform
 5:                         ensemble
 6:   imbalanced data,data transform
 7:                   data transform
 8:                   data transform
 9:                   data transform
10:                             meta
11:                   data transform
12:            encode,data transform
13:            encode,data transform
14:            encode,data transform
15:                         ensemble
16: feature selection,data transform
17:         robustify,data transform
18:                   data transform
19:                   data transform
20:                         missings
21:                         missings
22:                         missings
23:                         missings
24:                         missings
25:                         missings
26:                         missings
27:                         missings
28:                   data transform
29:                          learner
30:  learner,ensemble,data transform
31:          missings,data transform
32:                   data transform
33:                     multiplicity
34:                     multiplicity
35:                   data transform
36:                   data transform
37:                             meta
38:    target transform,multiplicity
39:            multiplicity,ensemble
40:                   data transform
41:                             meta
42:                   data transform
43:                   data transform
44:                         abstract
45:                         ensemble
46:         robustify,data transform
47:                   data transform
48:                     multiplicity
49:                   data transform
50:                   data transform
51:                   data transform
52: feature selection,data transform
53:   imbalanced data,data transform
54:                   data transform
55:                   data transform
56:                         abstract
57:                 target transform
58:                 target transform
59:                   data transform
60:                 target transform
61:                 target transform
62:                             meta
63:   encode,missings,data transform
64:                   data transform
                                tags
                                           feature_types input.num output.num
 1:                                      numeric,integer         1          1
 2:                                                   NA         1         NA
 3:                                                   NA         1         NA
 4: logical,integer,numeric,character,factor,ordered,...         1          1
 5:                                                   NA        NA          1
 6: logical,integer,numeric,character,factor,ordered,...         1          1
 7: logical,integer,numeric,character,factor,ordered,...         1          1
 8:                                       factor,ordered         1          1
 9: logical,integer,numeric,character,factor,ordered,...         1          1
10:                                                   NA         1         NA
11:                                              POSIXct         1          1
12:                                       factor,ordered         1          1
13:                                       factor,ordered         1          1
14:                                       factor,ordered         1          1
15:                                                   NA        NA          1
16: logical,integer,numeric,character,factor,ordered,...         1          1
17:                                       factor,ordered         1          1
18:                                      numeric,integer         1          1
19:                                      numeric,integer         1          1
20: logical,integer,numeric,character,factor,ordered,...         1          1
21:                                      integer,numeric         1          1
22:                               logical,factor,ordered         1          1
23:                                      numeric,integer         1          1
24:                                      numeric,integer         1          1
25:               factor,integer,logical,numeric,ordered         1          1
26:             character,factor,integer,numeric,ordered         1          1
27:               factor,integer,logical,numeric,ordered         1          1
28:                                      numeric,integer         1          1
29:                                                   NA         1          1
30: logical,integer,numeric,character,factor,ordered,...         1          1
31: logical,integer,numeric,character,factor,ordered,...         1          1
32: logical,integer,numeric,character,factor,ordered,...         1          1
33:                                                   NA         1         NA
34:                                                   NA        NA          1
35: logical,integer,numeric,character,factor,ordered,...         1          1
36:                                      numeric,integer         1          1
37:                                                   NA         1          1
38:                                                   NA         1          1
39:                                                   NA         1          1
40:                                      numeric,integer         1          1
41:                                                   NA        NA          1
42:                                      numeric,integer         1          1
43:                                      numeric,integer         1          1
44:                                                   NA         1          1
45:                                                   NA        NA          1
46: logical,integer,numeric,character,factor,ordered,...         1          1
47: logical,integer,numeric,character,factor,ordered,...         1          1
48:                                                   NA         1          1
49:                                      numeric,integer         1          1
50:                                      numeric,integer         1          1
51:                                      numeric,integer         1          1
52: logical,integer,numeric,character,factor,ordered,...         1          1
53: logical,integer,numeric,character,factor,ordered,...         1          1
54:                                      numeric,integer         1          1
55: logical,integer,numeric,character,factor,ordered,...         1          1
56:                                                   NA         2          1
57:                                                   NA         1          2
58:                                                   NA         1          2
59:                                            character         1          1
60:                                                   NA         1          1
61:                                                   NA         1          1
62:                                                   NA        NA          1
63: logical,integer,numeric,character,factor,ordered,...         1          1
64:                                      numeric,integer         1          1
                                           feature_types input.num output.num
    input.type.train  input.type.predict output.type.train output.type.predict
 1:             Task                Task              Task                Task
 2:                *                   *                 *                   *
 3:             Task                Task              Task                Task
 4:      TaskClassif         TaskClassif       TaskClassif         TaskClassif
 5:             NULL   PredictionClassif              NULL   PredictionClassif
 6:      TaskClassif         TaskClassif       TaskClassif         TaskClassif
 7:             Task                Task              Task                Task
 8:             Task                Task              Task                Task
 9:             Task                Task              Task                Task
10:                *                   *                 *                   *
11:             Task                Task              Task                Task
12:             Task                Task              Task                Task
13:             Task                Task              Task                Task
14:             Task                Task              Task                Task
15:             Task                Task              Task                Task
16:             Task                Task              Task                Task
17:             Task                Task              Task                Task
18:             Task                Task              Task                Task
19:             Task                Task              Task                Task
20:             Task                Task              Task                Task
21:             Task                Task              Task                Task
22:             Task                Task              Task                Task
23:             Task                Task              Task                Task
24:             Task                Task              Task                Task
25:             Task                Task              Task                Task
26:             Task                Task              Task                Task
27:             Task                Task              Task                Task
28:             Task                Task              Task                Task
29:      TaskClassif         TaskClassif              NULL   PredictionClassif
30:      TaskClassif         TaskClassif       TaskClassif         TaskClassif
31:             Task                Task              Task                Task
32:             Task                Task              Task                Task
33:              [*]                 [*]                 *                   *
34:                *                   *               [*]                 [*]
35:             Task                Task              Task                Task
36:             Task                Task              Task                Task
37:                *                   *                 *                   *
38:      TaskClassif         TaskClassif     [TaskClassif]       [TaskClassif]
39:           [NULL] [PredictionClassif]              NULL   PredictionClassif
40:             Task                Task              Task                Task
41:                *                   *                 *                   *
42:             Task                Task              Task                Task
43:             Task                Task              Task                Task
44:             NULL          Prediction              NULL          Prediction
45:             NULL      PredictionRegr              NULL      PredictionRegr
46:             Task                Task              Task                Task
47:             Task                Task              Task                Task
48:                *                   *               [*]                 [*]
49:             Task                Task              Task                Task
50:             Task                Task              Task                Task
51:             Task                Task              Task                Task
52:             Task                Task              Task                Task
53:             Task                Task              Task                Task
54:             Task                Task              Task                Task
55:             Task                Task              Task                Task
56:        NULL,NULL function,Prediction              NULL          Prediction
57:             Task                Task         NULL,Task       function,Task
58:         TaskRegr            TaskRegr     NULL,TaskRegr   function,TaskRegr
59:             Task                Task              Task                Task
60:             NULL   PredictionClassif              NULL   PredictionClassif
61:             Task                Task              NULL          Prediction
62:                *                   *                 *                   *
63:             Task                Task              Task                Task
64:             Task                Task              Task                Task
    input.type.train  input.type.predict output.type.train output.type.predict

Single POs can be created using the dictionary:

pca = mlr_pipeops$get("pca")

or using syntactic sugar po(<name>):

pca = po("pca")

Some POs require additional arguments for construction:

learner = po("learner")

# Error in as_learner(learner) : argument "learner" is missing, with no default argument "learner" is missing, with no default
learner = mlr_pipeops$get("learner", lrn("classif.rpart"))

or in short po("learner", lrn("classif.rpart")).

Hyperparameters of POs can be set through the param_vals argument. Here we set the fraction of features for a filter:

filter = po("filter",
  filter = mlr3filters::flt("variance"),
  param_vals = list(filter.frac = 0.5))

or in short notation:

po("filter", mlr3filters::flt("variance"), filter.frac = 0.5)

The figure below shows an exemplary PipeOp. It takes an input, transforms it during .$train and .$predict and returns data: