Skip to contents

Applies a Box-Cox transformation to the target variable to stabilize the variance, producing the new target BoxCox(y, lambda). The transformation is pointwise and monotonic, so no rows are dropped and predictions are inverted via forecast::InvBoxCox().

lambda = 0 is the log transformation. When lambda is NULL (default) it is estimated from the training data via forecast::BoxCox.lambda(), using the task frequency for the "guerrero" method so seasonality is accounted for. The estimated (or supplied) lambda is stored and reused at predict time and for inversion.

Box-Cox and log transformations require strictly positive target values; non-positive values produce NaN or an error from forecast::BoxCox().

Parameters

The parameters are the parameters inherited from mlr3pipelines::PipeOpTargetTrafo, as well as the following:

  • lambda :: numeric(1) | NULL
    Box-Cox transformation parameter. NULL (default) estimates it from the training data, 0 is the log transformation, any other numeric is used as a fixed value.

  • method :: character(1)
    Method used to estimate lambda when lambda = NULL, one of "guerrero" (default) or "loglik". See forecast::BoxCox.lambda().

  • lower :: numeric(1)
    Lower bound for the estimated lambda. Default -1.

  • upper :: numeric(1)
    Upper bound for the estimated lambda. Default 2.

Limitations

This PipeOp must not be placed inside a RecursiveForecaster or DirectForecaster graph. Inside RecursiveForecaster the transformation would entangle with the iterative lag/rolling feedback, which reads the original-scale backend, producing a train/predict scale mismatch (rejected at construction). Use inside a plain mlr3pipelines::GraphLearner via ppl("targettrafo", ...) for batch prediction, or wrap the forecaster itself with ppl("targettrafo", ...) so all horizons are inverted together.

Super classes

mlr3pipelines::PipeOp -> mlr3pipelines::PipeOpTargetTrafo -> PipeOpTargetTrafoBoxCox

Methods

Inherited methods


PipeOpTargetTrafoBoxCox$new()

Initializes a new instance of this Class.

Usage

PipeOpTargetTrafoBoxCox$new(id = "fcst.targetboxcox", param_vals = list())

Arguments

id

(character(1))
Identifier of resulting object, default "fcst.targetboxcox".

param_vals

(named list())
List of hyperparameter settings, overwriting the hyperparameter settings that would otherwise be set during construction. Default list().


PipeOpTargetTrafoBoxCox$clone()

The objects of this class are cloneable with this method.

Usage

PipeOpTargetTrafoBoxCox$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(mlr3pipelines)
task = tsk("airpassengers")
split = partition(task, ratio = 0.8)
flrn = as_learner(ppl("targettrafo",
  graph = DirectForecaster$new(lrn("regr.rpart"), lags = 1:3, horizons = length(split$test)),
  trafo_pipeop = po("fcst.targetboxcox")
))
flrn$train(task, split$train)
flrn$predict(task, split$test)
#> 
#> ── <PredictionRegr> for 29 observations: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>  row_ids truth response
#>      116   505 409.4023
#>      117   404 360.7524
#>      118   359 303.4957
#>      ---   ---      ---
#>      142   461 360.4986
#>      143   390 340.1683
#>      144   432 356.7078