Skip to contents

Differences the target variable with lag lag, producing the new target y'_t = y_t - y_{t - lag}. The first lag rows are dropped during training and predictions are inverted back to the original scale. On keyed (multi-series) tasks this happens within each series. Series too short for the requested lag are dropped with a warning, and predicting a series not seen during training is an error.

Use lag = 1 to remove a trend and lag = 12 (or the seasonal period) to remove seasonality.

Parameters

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

  • lag :: integer(1)
    Lag to difference at. Default 1L.

Limitations

This PipeOp must not be placed inside a RecursiveForecaster or DirectForecaster graph and is rejected at construction. Use it inside a plain mlr3pipelines::GraphLearner via ppl("targettrafo", ...), or wrap the forecaster itself with ppl("targettrafo", ...) so all horizons are inverted together.

Quantile predictions cannot be inverted and are rejected.

Super classes

mlr3pipelines::PipeOp -> mlr3pipelines::PipeOpTargetTrafo -> PipeOpTargetTrafoDifference

Methods

Inherited methods


PipeOpTargetTrafoDifference$new()

Initializes a new instance of this Class.

Usage

PipeOpTargetTrafoDifference$new(id = "fcst.targetdiff", param_vals = list())

Arguments

id

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

param_vals

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


PipeOpTargetTrafoDifference$clone()

The objects of this class are cloneable with this method.

Usage

PipeOpTargetTrafoDifference$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# \donttest{
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.targetdiff", lag = 1L)
))
flrn$train(task, split$train)
flrn$predict(task, split$test)
#> 
#> ── <PredictionFcst> for 29 observations: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>       month row_ids truth response
#>  1958-08-01     116   505 461.5000
#>  1958-09-01     117   404 429.9286
#>  1958-10-01     118   359 392.4286
#>         ---     ---   ---      ---
#>  1960-10-01     142   461 479.7749
#>  1960-11-01     143   390 485.7124
#>  1960-12-01     144   432 498.3552
# }