## 5.1 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. library("mlr3pipelines") as.data.table(mlr_pipeops) #> key packages input.num output.num input.type.train #> 1: apply 1 1 Task #> 2: backuplearner 2 1 NULL,Task #> 3: balancesample 1 1 Task #> 4: branch 1 NA * #> 5: chunk 1 NA Task #> 6: copy 1 NA * #> 7: encode stats 1 1 Task #> 8: featureunion NA 1 Task #> 9: filter 1 1 Task #> 10: impute 1 1 Task #> 11: learner 1 1 Task #> 12: learner_cv 1 1 Task #> 13: majorityvote NA 1 NULL #> 14: modelavg NA 1 NULL #> 15: mutate 1 1 Task #> 16: null 1 1 * #> 17: pca 1 1 Task #> 18: scale 1 1 Task #> 19: select 1 1 Task #> 20: subsample 1 1 Task #> 21: unbranch NA 1 * #> key packages input.num output.num input.type.train #> input.type.predict output.type.train output.type.predict #> 1: Task Task Task #> 2: Prediction,Task NULL Prediction #> 3: Task Task Task #> 4: * * * #> 5: Task Task Task #> 6: * * * #> 7: Task Task Task #> 8: Task Task Task #> 9: Task Task Task #> 10: Task Task Task #> 11: Task NULL Prediction #> 12: Task Task Task #> 13: PredictionClassif NULL PredictionClassif #> 14: PredictionRegr NULL PredictionRegr #> 15: Task Task Task #> 16: * * * #> 17: Task Task Task #> 18: Task Task Task #> 19: Task Task Task #> 20: Task Task Task #> 21: * * * #> input.type.predict output.type.train output.type.predict Single POs can be created using mlr_pipeops$get(<name>).

pca = mlr_pipeops$get("pca") Some POs require additional arguments for construction. learner = mlr_pipeops$get("learner")

# Error in cast_from_dict(learner, "Learner", mlr_learners, clone, FALSE) : argument "learner" is missing, with no default
learner = mlr_pipeops$get("learner", mlr_learners$get("classif.ranger"))

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

filter = mlr_pipeops$get("filter", filter = mlr3featsel::FilterVariance$new(),
param_vals = list(filter.frac = 0.5))

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