CPOs Built Into mlrCPO (No Output)

Martin Binder

2020-02-23

CPO Vignette Navigation

  1. First Steps (compact version)
  2. mlrCPO Core (compact version)
  3. CPOs Built Into mlrCPO (compact version)
  4. Building Custom CPOs (compact version)

Listing CPOs

Builtin CPOs can be listed with listCPO().

listCPO()[, c("name", "category", "subcategory")]

NULLCPO

NULLCPO is the neutral element of %>>%. It is returned by some functions when no other CPO or Retrafo is present.

NULLCPO
is.nullcpo(NULLCPO)
NULLCPO %>>% cpoScale()
NULLCPO %>>% NULLCPO
print(as.list(NULLCPO))
pipeCPO(list())

Meta-CPO

cpoWrap

A simple CPO with one parameter which gets applied to the data as CPO. This is different from a multiplexer in that its parameter is free and can take any value that behaves like a CPO. On the downside, this does not expose the argument’s parameters to the outside.

cpoMultiplex

Combine many CPOs into one, with an extra selected.cpo parameter that chooses between them.

cpoCase

A CPO that builds data-dependent CPO networks. This is a generalized CPO-Multiplexer that takes a function which decides (from the data, and from user-specified hyperparameters) what CPO operation to perform. Besides optional arguments, the used CPO’s Hyperparameters are exported as well. This is a generalization of cpoMultiplex; however, requires of the involved parameters are not adjusted, since this is impossible in principle.

The resulting CPO s.and.p performs scaling and PCA, with the order depending on the parameter logical.param and on whether the mean of the data’s first column exceeds 10. If either of those is true, the data will be first scaled, then PCA’d, otherwise the order is reversed. The all CPOs listed in .export are passed to the cpo.build.

cpoCbind

cbind other CPOs as operation. The cbinder makes it possible to build DAGs of CPOs that perform different operations on data and paste the results next to each other.

cpoTransformParams

cpoTransformParams wraps another CPO and sets some of its hyperparameters to the value of expressions depending on other hyperparameter values. This can be used to make a transformation of parameters similar to the trafo parameter of a Param in ParamHelpers, but it can also be used to set multiple parameters at the same time, depending on a single new parameter.

Data Manipulation

cpoScale

Implements the base::scale function.

cpoPca

Implements stats::prcomp. No scaling or centering is performed.

cpoDummyEncode

Dummy encoding of factorial variables. Optionally uses the first factor as reference variable.

cpoSelect

Select to use only certain columns of a dataset. Select by column index, name, or regex pattern.

cpoDropConstants

Drops constant features or numerics, with variable tolerance

cpoFixFactors

Drops unused factors and makes sure prediction data has the same factor levels as training data.

cpoMissingIndicators

Creates columns indicating missing data. Most useful in combination with cpoCbind.

cpoApplyFun

Apply an univariate function to data columns

cpoAsNumeric

Convert (non-numeric) features to numeric

cpoCollapseFact

Combine low prevalence factors. Set max.collapsed.class.prevalence how big the combined factor level may be.

cpoModelMatrix

Specify which columns get used, and how they are transformed, using a formula.

cpoScaleRange

scale values to a given range

cpoScaleMaxAbs

Multiply features to set the maximum absolute value.

cpoSpatialSign

Normalize values row-wise

Imputation

There are two general and many specialised imputation CPOs. The general imputation CPOs have parameters that let them use different imputation methods on different columns. They are a thin wrapper around mlr’s impute() and reimpute() functions. The specialised imputation CPOs each implement exactly one imputation method and are closer to the behaviour of typical CPOs.

General Imputation Wrappers

cpoImpute and cpoImputeAll both have parameters very much like impute(). The latter assumes that all columns of its input is somehow being imputed and can be preprended to a learner to give it the ability to work with missing data. It will, however, throw an error if data is missing after imputation.

Specialised Imputation Wrappers

There is one for each imputation method.

Feature Filtering

There is one general and many specialised feature filtering CPOs. The general filtering CPO, cpoFilterFeatures, is a thin wrapper around filterFeatures and takes the filtering method as its argument. The specialised CPOs each call a specific filtering method.

Most arguments of filterFeatures are reflected in the CPOs. The exceptions being: 1. for filterFeatures, the filter method arguments are given in a list filter.args, instead of in ... 2. The argument fval was dropped for the specialised filter CPOs. 3. The argument mandatory.feat was dropped. Use affect.* parameters to prevent features from being filtered.

head(getTaskData(iris.task %>>% cpoFilterFeatures(method = "variance", perc = 0.5)))
head(getTaskData(iris.task %>>% cpoFilterVariance(perc = 0.5)))
# The specialised filter CPOs are:
listCPO()[listCPO()$category == "featurefilter" & listCPO()$subcategory == "specialised",
          c("name", "description")]