CPO objects are created by calling CPOConstructors, which are R functions that have some parameters in common, use a convenient print.CPOConstructor generic, and always return a CPO object. The mlrCPO package provides many CPOConstructor functions, which can be listed using listCPO. It is also possible to create custom CPOConstructors using makeCPO, makeCPORetrafoless, link{makeCPOTargetOp}, and makeCPOExtendedTrafo.

Arguments

id

[character(1) | NULL]
ID to use for the CPO. if NULL is given, this defaults to a name describing the action performed by the CPO, which can be retrieved using getCPOName. The ID is used to identify the CPO in print messages, and is prefixed to the CPO's hyperparameter names. This is can be used to avoid name clashes when composing a CPO with another CPO or Learner with hyperparameters with clashing names. Default is NULL.

export

[character]
Which hyperparameters to export. This can be a character vector naming the hyperparameters to export (excluding the ID), or a character(1) with one of the special values:

“export.all”export all parameters
“export.default”exp. params that are exp. by def
“export.set”exp. params set in construct call
“export.default.set”intersection of “default” and “set”
“export.unset”params not set in construct call
“export.default.unset”isct. of “default” and “unset”
“export.all.plus”not yet supported

Default is “export.default”.

affect.type

[character | NULL]
Type of columns to affect. May be a subset of “numeric”, “factor”, “ordered”, “other”, or can be or NULL to match all columns. Default is NULL.

affect.index

[numeric]
Indices of feature columns to affect. The order of indices given is respected. Default is integer(0).

affect.names

[character]
Feature names of feature columns to affect. The order of names given is respected. Default is character(0).

affect.pattern

[character(1) | NULL]
grep pattern to match feature names by. Default is NULL (no pattern matching)

affect.invert

[logical(1)]
Whether to affect all features not matched by other affect.* parameters. Default is FALSE.

affect.pattern.ignore.case

[logical(1)]
Ignore case when matching features with affect.pattern; see grep. Has no effect when affect.pattern is NULL. Default is FALSE.

affect.pattern.perl

[logical(1)]
Use Perl-style regular expressions for affect.pattern; see grep. Has no effect when affect.pattern is NULL, or when affect.pattern.fixed is TRUE. Default is FALSE.

affect.pattern.fixed

[logical(1)]
Use fixed matching instead of regular expressions for affect.pattern; see grep. Has no effect when affect.pattern is NULL. Default is FALSE.

Value

[CPO] the constructed CPO.

CPO creation

CPOConstructors can be called like any R function, with any parameters given. Besides parameters that are common to most CPOConstructors (listed below), it is possible to set CPO-specific hyperparameters in the construction. Parameters that are being exported can also be modified later using the CPO object, see the documentation there.

affect.* parameters

When creating a CPO, it is possible to choose which columns of the given data the CPO operates on, and which columns it will ignore. This is done using the affect.* parameters. It is possible to choose columns by types, indices, names, or a regular expression matching names.

See also

print.CPOConstructor for possibly verbose printing.

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

Other CPOConstructor related: getCPOClass(), getCPOConstructor(), getCPOName(), identicalCPO(), makeCPO(), print.CPOConstructor()

Examples

class(cpoPca) # c("CPOConstructor", "function")
#> [1] "CPOConstructor" "function"
print(cpoPca) # default printer
#> <<CPO pca(center = TRUE, scale = FALSE, tol = <NULL>, rank = <NULL>)>>
print(cpoPca, verbose = TRUE) # shows the trafo / retrafo functions
#> <<CPO pca(center = TRUE, scale = FALSE, tol = <NULL>, rank = <NULL>)>> #> #> cpo.trafo: #> function (center = TRUE, scale = FALSE, tol = NULL, rank = NULL, #> data, target) #> { #> if (!ncol(data)) { #> emat = matrix(data = numeric(0), nrow = 0, ncol = 0) #> control = list(rotation = emat, scale = numeric(0), center = numeric(0)) #> return(data) #> } #> pcr = prcomp(as.matrix(data), center = center, scale. = scale, #> tol = tol, rank = rank) #> control = pcr[c("rotation", "scale", "center")] #> pcr$x #> } #> <environment: namespace:mlrCPO> #> #> cpo.retrafo: #> function (center = TRUE, scale = FALSE, tol = NULL, rank = NULL, #> data, control) #> { #> scale(as.matrix(data), center = control$center, scale = control$scale) %*% #> control$rotation #> } #> <environment: namespace:mlrCPO>
cpoPca() # creating a CPO
#> pca(center = TRUE, scale = FALSE)[not exp'd: tol = <NULL>, rank = <NULL>]
class(cpoPca()) # c("CPOPrimitive", "CPO")
#> [1] "CPOPrimitive" "CPO"