Classical · ARIMA with statsmodels.
arima_forecast.pypython
import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
# Load and fit
df = pd.read_csv("ETTh1.csv", parse_dates=["date"], index_col="date")
series = df["OT"] # Oil Temperature target
model = ARIMA(series, order=(2, 1, 2)) # (p, d, q)
fitted = model.fit()
# Forecast next 96 steps
forecast = fitted.forecast(steps=96)
print(f"AIC: {fitted.aic:.1f}")
print(forecast.head())
Transformer · PatchTST with HuggingFace.
patchtst_forecast.pypython
from transformers import PatchTSTForPrediction, PatchTSTConfig
import torch
config = PatchTSTConfig(
num_input_channels=7, # ETTh1 has 7 features
context_length=512, # lookback window
prediction_length=96, # forecast horizon
patch_length=16, # each patch = 16 time steps
stride=8, # overlap between patches
d_model=128,
num_attention_heads=4,
num_hidden_layers=3,
)
model = PatchTSTForPrediction(config)
# Shape: (batch, channels, context_length)
past_values = torch.randn(32, 7, 512)
outputs = model(past_values=past_values)
# outputs.prediction_outputs: (32, 7, 96)
predictions = outputs.prediction_outputs
print(f"Forecast shape: {predictions.shape}")
Foundation · Chronos (zero-shot, probabilistic).
chronos_forecast.pypython
import torch
from chronos import ChronosPipeline
pipeline = ChronosPipeline.from_pretrained(
"amazon/chronos-t5-base", # 200M params
device_map="cuda",
torch_dtype=torch.bfloat16,
)
# Context: last 512 observations
context = torch.tensor(df["OT"].values[-512:])
# Generate 96-step probabilistic forecast
forecast = pipeline.predict(
context=context,
prediction_length=96,
num_samples=20,
)
median = forecast.median(dim=1).values
low = forecast.quantile(0.1, dim=1).values
high = forecast.quantile(0.9, dim=1).values
print(f"Median forecast: {median.shape}")
print(f"80% interval width: {(high - low).mean():.4f}")
Foundation · TimesFM (zero-shot, point).
timesfm_forecast.pypython
import timesfm
tfm = timesfm.TimesFm(
context_len=512,
horizon_len=96,
input_patch_len=32,
output_patch_len=128,
num_layers=20,
model_dims=1280,
backend="gpu",
)
tfm.load_from_checkpoint(repo_id="google/timesfm-1.0-200m")
forecast_input = df["OT"].values[-512:]
point_forecast, experimental_quantiles = tfm.forecast(
[forecast_input],
freq=[0], # 0 = high-frequency (hourly)
)
print(f"Point forecast shape: {point_forecast.shape}")