Skip to content

Add optional insample parameter to inverse_transform() of data transformers and pipeline for simpler Diff handling #3045

@dennisbader

Description

@dennisbader

Inverse-transforming forecasts with the Diff transformer is tedious. It requires prepending the transformed insample target series to the forecasts for inverse_transform() to work.

We could add an optional parameter insample: TimeSeriesLike | None = None to inverse_transform() of InvertibleDataTransformer and Pipeline, that would simplify this process for the user.

This parameter would at the moment only be used by the Diff transformer and ignored by others.

Some requirements:

  • The insample time series must be the transformed target series returned by Diff().fit_transform(series)
  • Time frame:
    • It must start at the same time as the transformed target series
    • It must extend to at least one step before forecast start, but it can extend further into the future.
  • Similar to how we handle insample for metrics such as mase(), we would extract the relevant parts of the series and prepend it the (forecast) series pass to Diff.inverse_transform()

Expected user flow:

from darts.dataprocessing.transformers import Diff
from darts.datasets import AirPassengersDataset
from darts.models import NaiveSeasonal

# `Diff()` or `Pipeline([Diff()])`
tf = Diff()
series = AirPassengersDataset().load()

series_tf = tf.fit_transform(series)

pred_tf = NaiveSeasonal(K=12).fit(series).predict(n=12)

pred = tf.inverse_transform(pred_tf, insample=series_tf)

That means that the data transformer handling in historical forecasts should also always pass the insample series.

Metadata

Metadata

Assignees

Labels

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions