This is a CPOConstructor to be used to create a CPO. It is called like any R function and returns the created CPO.

Oversamples the minor or undersamples the major class in a binary classification task to alleviate class imbalance. Uses mlr::oversample and mlr::undersample, see documentation there.

cpoOversample(rate = NULL, cl = NULL, id, export = "export.default")

cpoUndersample(rate = NULL, cl = NULL, id, export = "export.default")



[numeric(1) | NULL]
Factor to up- or downsample a class. Must be between 0 and 1 for undersampling and greater or equal 1 for oversampling. If this is NULL, this is the ratio of major to minor class prevalence (for oversampling, or the inverse for undersampling). Must not be NULL if cl is not NULL and not the minor class for oversampling / the major class for undersampling. Default is NULL.


[character(1) | NULL]
Class to over- or undersample. For NULL, the minor class for oversampling or the major class for undersampling is chosen automatically.


id to use as prefix for the CPO's hyperparameters. this must be used to avoid name clashes when composing two CPOs of the same type, or with learners or other CPOS with hyperparameters with clashing names.


Either a character vector indicating the parameters to export as hyperparameters, or one of the special values “export.all” (export all parameters), “export.default” (export all parameters that are exported by default), “export.set” (export all parameters that were set during construction), “export.default.set” (export the intersection of the “default” and “set” parameters), “export.unset” (export all parameters that were not set during construction) or “export.default.unset” (export the intersection of the “default” and “unset” parameters). Default is “export.default”.



General CPO info

This function creates a CPO object, which can be applied to Tasks, data.frames, link{Learner}s and other CPO objects using the %>>% operator.

The parameters of this object can be changed after creation using the function setHyperPars. The other hyper-parameter manipulating functins, getHyperPars and getParamSet similarly work as one expects.

If the “id” parameter is given, the hyperparameters will have this id as aprefix; this will, however, not change the parameters of the creator function.

Calling a CPOConstructor

CPO constructor functions are called with optional values of parameters, and additional “special” optional values. The special optional values are the id parameter, and the affect.* parameters. The affect.* parameters enable the user to control which subset of a given dataset is affected. If no affect.* parameters are given, all data features are affected by default.

See also