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. Predictions are inverted via stride-lag cumulative sums anchored at the last lag training values, yielding original-scale predictions.

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. Inside RecursiveForecaster, the trafo only transforms the active row at predict time while iterative features (lags, rolling windows) need transformed values for all historical rows. Inside DirectForecaster, each horizon is inverted independently against the training tail, which is wrong for horizons >= 2. 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 -> 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

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)
#> 
#> ── <PredictionRegr> for 29 observations: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>  row_ids truth response
#>      116   505 461.5000
#>      117   404 429.9286
#>      118   359 398.3571
#>      ---   ---      ---
#>      142   461 490.1575
#>      143   390 496.0987
#>      144   432 508.4737