Implementation:Sktime Pytorch forecasting Generate Ar Data
| Knowledge Sources | |
|---|---|
| Domains | Time_Series, Data_Engineering, Experimentation |
| Last Updated | 2026-02-08 07:00 GMT |
Overview
Concrete tool for generating synthetic autoregressive time series data provided by the pytorch-forecasting library.
Description
The generate_ar_data function creates a DataFrame of synthetic multivariate time series without covariates. Each series is generated from a combination of linear trend, quadratic trend, sinusoidal seasonality, and Gaussian noise with controllable parameters. The output DataFrame has three columns: series (group identifier), time_idx (integer time index), and value (target). This is the canonical data source for DeepAR and N-BEATS examples.
Usage
Import this function when you need synthetic univariate time series data for testing or demonstrating DeepAR or N-BEATS models. The function provides reproducible data via a seed parameter. Canonical usage for DeepAR: generate_ar_data(seasonality=10.0, timesteps=400, n_series=100).
Code Reference
Source Location
- Repository: pytorch-forecasting
- File: pytorch_forecasting/data/examples.py
- Lines: L53-111
Signature
def generate_ar_data(
n_series: int = 10,
timesteps: int = 400,
seasonality: float = 3.0,
trend: float = 3.0,
noise: float = 0.1,
level: float = 1.0,
exp: bool = False,
seed: int = 213,
) -> pd.DataFrame:
"""
Generate multivariate data without covariates.
Each timeseries is generated from seasonality and trend.
Args:
n_series: Number of series. Defaults to 10.
timesteps: Number of timesteps. Defaults to 400.
seasonality: Normalized frequency. Defaults to 3.0.
trend: Trend multiplier. Defaults to 3.0.
noise: Level of gaussian noise. Defaults to 0.1.
level: Level multiplier. Defaults to 1.0.
exp: If to return exponential of values. Defaults to False.
seed: Random seed. Defaults to 213.
Returns:
pd.DataFrame: data with columns series, time_idx, value
"""
Import
from pytorch_forecasting.data.examples import generate_ar_data
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| n_series | int | No | Number of independent series to generate (default: 10) |
| timesteps | int | No | Length of each series (default: 400) |
| seasonality | float | No | Normalized frequency of seasonal component (default: 3.0) |
| trend | float | No | Trend multiplier (default: 3.0) |
| noise | float | No | Gaussian noise level (default: 0.1) |
| level | float | No | Level multiplier for series amplitude (default: 1.0) |
| exp | bool | No | Whether to exponentiate values (default: False) |
| seed | int | No | Random seed for reproducibility (default: 213) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | pd.DataFrame | DataFrame with columns: series (int group id), time_idx (int time index), value (float target) |
Usage Examples
DeepAR Data Generation
from pytorch_forecasting.data.examples import generate_ar_data
# Generate 100 series with strong seasonality for DeepAR
data = generate_ar_data(seasonality=10.0, timesteps=400, n_series=100)
print(data.head())
# series time_idx value
# 0 0 0 0.123456
# 1 0 1 0.234567
# ...
# Split into training and validation
training_cutoff = data["time_idx"].max() - 20
training = data[lambda x: x.time_idx <= training_cutoff]
validation = data
N-BEATS Data Generation
from pytorch_forecasting.data.examples import generate_ar_data
# Generate data for N-BEATS univariate forecasting
data = generate_ar_data(seasonality=10.0, timesteps=400, n_series=100, seed=42)
# Add static grouping column (N-BEATS example pattern)
data["static"] = 0
# Define training cutoff
context_length = 150
prediction_length = 20
training_cutoff = data["time_idx"].max() - prediction_length