Implementation:Sktime Pytorch forecasting DLinear V2
| Knowledge Sources | |
|---|---|
| Domains | Time_Series, Forecasting, Deep_Learning |
| Last Updated | 2026-02-08 08:00 GMT |
Overview
DLinear is a decomposition-linear model for long-term time series forecasting that separates trend and seasonal components and processes each with simple linear layers.
Description
DLinear extends TslibBaseModel and implements the LTSF-DLinear architecture from the Time-Series-Library. The model decomposes input time series into trend and seasonal components using a moving average filter (SeriesDecomposition), then applies separate linear layers to each component. The final prediction is the sum of the trend and seasonal projections. This is an experimental V2 implementation built on the TslibBaseModel pipeline and supports both shared and individual per-variate linear layers, as well as quantile loss for probabilistic forecasting.
Usage
Use DLinear when you need a simple, fast, and interpretable baseline for long-term time series forecasting. It is particularly effective when the underlying patterns can be well captured by linear transformations of trend and seasonal components. Note that this is an experimental V2 implementation and its API may change.
Code Reference
Source Location
- Repository: Sktime_Pytorch_forecasting
- File: pytorch_forecasting/models/dlinear/_dlinear_v2.py
- Lines: 1-307
Signature
class DLinear(TslibBaseModel):
def __init__(
self,
loss: nn.Module,
moving_avg: int = 25,
individual: bool = False,
logging_metrics: list[nn.Module] | None = None,
optimizer: Optimizer | str | None = "adam",
optimizer_params: dict | None = None,
lr_scheduler: str | None = None,
lr_scheduler_params: dict | None = None,
metadata: dict | None = None,
**kwargs: Any,
):
Import
from pytorch_forecasting.models.dlinear._dlinear_v2 import DLinear
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| loss | nn.Module | Yes | Loss function for training (e.g. MSELoss, QuantileLoss). |
| moving_avg | int | No | Kernel size for moving average decomposition. Defaults to 25. |
| individual | bool | No | Whether to use individual linear layers per variate (True) or shared (False). Defaults to False. |
| logging_metrics | None | No | Metrics to log during training. Defaults to None. |
| optimizer | str | None | No | Optimizer for training. Defaults to "adam". |
| optimizer_params | None | No | Parameters for the optimizer. Defaults to None. |
| lr_scheduler | None | No | Learning rate scheduler name. Defaults to None. |
| lr_scheduler_params | None | No | Parameters for the LR scheduler. Defaults to None. |
| metadata | None | No | Metadata from TslibDataModule with dataset shape information. Defaults to None. |
Outputs
| Name | Type | Description |
|---|---|---|
| prediction | torch.Tensor | Forecast output of shape (batch_size, prediction_length, target_dim) or (batch_size, prediction_length, n_quantiles) when using QuantileLoss. |
Usage Examples
from pytorch_forecasting.models.dlinear._dlinear_v2 import DLinear
from pytorch_forecasting.metrics import QuantileLoss
import torch.nn as nn
# Instantiate with MSE loss
model = DLinear(
loss=nn.MSELoss(),
moving_avg=25,
individual=False,
optimizer="adam",
optimizer_params={"lr": 1e-3},
metadata=metadata,
)
# Instantiate with quantile loss for probabilistic forecasting
model = DLinear(
loss=QuantileLoss(),
moving_avg=25,
individual=True,
metadata=metadata,
)
# Forward pass
output = model(x_batch)
predictions = output["prediction"]
Related Pages
- Principle:Sktime_Pytorch_forecasting_Decomposition_Linear
- Sktime_Pytorch_forecasting_TFT_V2 - Alternative V2 model with attention mechanisms