| CPOTrained | R Documentation |
When applying a CPO to a data.frame or Task,
the data is not only changed, additionally a retransformation and an inversion
object is created that can be applied to other data of the same
kind. This is useful if new data (for prediction or validation) is to be handled in the same machine learning
procedure.
For example, when performing PCA on training data using cpoPca, the rotation
matrix is saved and can be used on new (prediction) data. As another example, consider
a log-transformation of the target column in a regression problem. When predictions are made with
new data, it may be useful to invert the transformation on the predicted values by exponentiating them.
The information created when a CPO is applied is saved in a CPORetrafo object, and a CPOInverter
object, which are both saved as attributes. The retrafo and inverter function
retrieve these objects. It is furthermore possible to set these attributes using the retrafo<-
and inverter<- functions, using constructs like retrafo(data) <- retr.obj. The retrafo
or inverter attributes can be reset individually by setting them to NULL:
retrafo(data) <- NULL, or by using the clearRI function.
When chaining %>>% on a data object, the retrafo and inverter
associated with the result is also chained automatically. Beware,
however, that this just accesses the retrafo attribute internally. Therefore, if you plan to do apply
multiple transformations with other operations in between,
make sure to reset the retrafo function by setting it to NULL, or using the clearRI
function. See examples.
retrafo(data)
inverter(data)
retrafo(data) <- value
inverter(data) <- value
data |
[ |
value |
[ |
[CPOTrained]. The retransformation function that can be
applied to new data. This is a CPORetrafo object for retrafo
or a CPOInverter object for inverter.
CPORetrafo and CPOInverterCPORetrafo and CPOInverter objects are members of the CPOTrained class, which can be handled similarly to CPO objects:
Their hyperparameters can be inspected using getParamSet and link[mlr]{getHyperPars},
print.CPOTrained is used for (possibly verbose) printing. To apply the retrafo or inverter transformation represented by the
object to data, use the applyCPO or %>>% function.
CPOTrained objects can be chained using %>>% or pipeCPO, and broken into primitives using as.list.CPOTrained.
However, since the CPOTrained objects represent transformations that relate closely to the data used to train it (and therefore
to the position within a CPO pipeline), it is only advisable to chain or break apart CPOTrained pipes for inspection, or
if you really know what you are doing.
(Primitive) CPORetrafo objects can be inspected using getCPOTrainedState, and it is possible to create new CPORetrafo
objects from (possibly modified) retrafo state using makeCPOTrainedFromState.
CPORetrafo and CPOInverterThe fundamental difference between CPORetrafo and CPOInverter is that a CPORetrafo is
created only when a CPO is applied to a data set, and is used to perform the same transformation on new
(prediction) data. The CPOInverter is created whenever a CPO or CPORetrafo is
applied to data (whether training or prediction data). It is in fact used to invert the transformation done to the target
column of a Task. Since this operation may depend on the new prediction data, and not only on the training
data fed to the CPO when the CPORetrafo was created, the CPOInverter object is more
closely bound to the particular data set used to create it.
In some cases a target transformation is independent of the data used to create it (e.g. log-transform of a regression target
column); in that case the CPORetrafo can be used with invert. This is the concept of
CPOTrainedCapability, which can be queried using getCPOTrainedCapability.
CPORetrafoCPORetrafo objects can be applied to new data sets using the %>>% operator, the
applyCPO generic, or the predict generic, all of which perform the same action.
CPOInverterTo use a CPOInverter, use the invert function.
clearRI about the problem of needing to reset retrafo and inverter attributes sometimes.
Other CPO lifecycle related:
CPO,
CPOConstructor,
CPOLearner,
NULLCPO,
%>>%(),
attachCPO(),
composeCPO(),
getCPOClass(),
getCPOConstructor(),
getCPOTrainedCPO(),
identicalCPO(),
makeCPO()
Other retrafo related:
NULLCPO,
%>>%(),
applyCPO(),
as.list.CPO,
clearRI(),
getCPOClass(),
getCPOName(),
getCPOOperatingType(),
getCPOPredictType(),
getCPOProperties(),
getCPOTrainedCPO(),
getCPOTrainedCapability(),
getCPOTrainedState(),
is.retrafo(),
makeCPOTrainedFromState(),
pipeCPO(),
print.CPOConstructor()
Other inverter related:
NULLCPO,
%>>%(),
applyCPO(),
as.list.CPO,
clearRI(),
getCPOClass(),
getCPOName(),
getCPOOperatingType(),
getCPOPredictType(),
getCPOProperties(),
getCPOTrainedCPO(),
getCPOTrainedCapability(),
getCPOTrainedState(),
is.inverter(),
makeCPOTrainedFromState(),
pipeCPO(),
print.CPOConstructor()
traindat = subsetTask(pid.task, 1:400)
preddat = subsetTask(pid.task, 401:768)
trained = traindat %>>% cpoPca()
reFun = retrafo(trained)
predicted = preddat %>>% reFun
head(getTaskData(predicted))
# chaining works
trained = traindat %>>% cpoPca() %>>% cpoScale()
reFun = retrafo(trained)
predicted = preddat %>>% reFun
head(getTaskData(predicted))
# reset the retrafo when doing other steps!
trained.tmp = traindat %>>% cpoPca()
reFun1 = retrafo(trained.tmp)
imp = impute(trained.tmp)
trained.tmp = imp$task # nonsensical example
retrafo(trained.tmp) = NULL # NECESSARY HERE
trained = trained.tmp %>>% cpoScale()
reFun2 = retrafo(trained)
predicted = getTaskData(reimpute(preddat %>>% reFun1, imp$desc),
target.extra = TRUE)$data %>>% reFun2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.