grapes-greater-than-greater-than-grapes: CPO Composition / Attachment / Application Operator

%>>%R Documentation

CPO Composition / Attachment / Application Operator

Description

This operator “pipes” data from the source into the sink object.

If both objects are a CPO object, or both are a CPOTrained object, they will be composed. A new object, representing the operation of performing both object's operations in succession, will be created, which can be handled like a new CPO or CPOTrained object. See composeCPO.

If the source object is a data.frame or a link[mlr]{Task}, the transformation operation will be applied to this data, and the same resulting data will be returned. See applyCPO.

If the sink object is a Learner, the CPO will be attached to this learner. The same operation will be performed during the train and predict phase; the behaviour during the predict phase may furthermore be depend on the training data. See attachCPO.

Note that you can not link a data.frame or Task directly to a Learner, since this operation is not algebraically associative with the composition of CPOs. Use train for this.

The %<<% operator is synonymous with %>>% with source and sink argument swapped.

The %>|% and %|<% operators perform piping followed by application of retrafo. The %>|% evaluates the expression to its right before the expression to its left, so it may be used in the most natural way without parentheses:

data %>|% cpo1 %>>% cpo2

is the same as

retrafo(data %>>% cpo1 %>>% cpo2).

The %<>>% and %<<<% operators perform the piping operation and assign the result to the left hand variable. This way it is possible to apply a CPO, or to attach a CPO to a Learner, and just keep the resulting object. The assignment operators evaluate their right hand side before their left hand side, so it is possible to build long chains that end up writing to the leftmost variable. Therefore the expression

data %<>>% cpo1 %<>>% cpo2 %>>% cpo3

is the same as

cpo1 = cpo1 %>>% cpo2 %>>% cpo3
data = data %>>% cpo1

Usage

cpo1 %>>% cpo2

cpo2 %<<% cpo1

cpo1 %<>>% cpo2

cpo2 %<<<% cpo1

cpo1 %>|% cpo2

cpo2 %|<% cpo1

Arguments

cpo1

[data.frame | Task | CPO | CPOTrained]
The source object.

cpo2

[CPO | CPOTrained | Learner]
The sink object.

Value

[data.frame | Task | CPO | CPOTrained].

See Also

Other operators: CPO, applyCPO(), as.list.CPO, attachCPO(), composeCPO(), pipeCPO()

Other retrafo related: CPOTrained, NULLCPO, applyCPO(), as.list.CPO, clearRI(), getCPOClass(), getCPOName(), getCPOOperatingType(), getCPOPredictType(), getCPOProperties(), getCPOTrainedCPO(), getCPOTrainedCapability(), getCPOTrainedState(), is.retrafo(), makeCPOTrainedFromState(), pipeCPO(), print.CPOConstructor()

Other inverter related: CPOTrained, NULLCPO, applyCPO(), as.list.CPO, clearRI(), getCPOClass(), getCPOName(), getCPOOperatingType(), getCPOPredictType(), getCPOProperties(), getCPOTrainedCPO(), getCPOTrainedCapability(), getCPOTrainedState(), is.inverter(), makeCPOTrainedFromState(), pipeCPO(), print.CPOConstructor()

Other CPO lifecycle related: CPOConstructor, CPOLearner, CPOTrained, CPO, NULLCPO, attachCPO(), composeCPO(), getCPOClass(), getCPOConstructor(), getCPOTrainedCPO(), identicalCPO(), makeCPO()

Examples

# PCA-rotate pid.task
rotated.pid.task = pid.task %>>% cpoScale() %>>% cpoPca()

# Centering / Scaling *after* PCA
newPCA = cpoPca() %>>% cpoScale()

# Attach the above to learner
pcaLogreg = newPCA %>>% makeLearner("classif.logreg")

# append cpoAsNumeric to newPCA
newPCA %<>>% cpoAsNumeric()
print(newPCA)

# prepend cpoAsNumeric to pcaLogreg
pcaLogreg %<<<% cpoAsNumeric()


mlr-org/mlrCPO documentation built on Nov. 18, 2022, 11:25 p.m.