Skip to main content

Overview

LPTM (Large Pre-trained Time-series Model) is a foundation model for time series analysis that supports multiple tasks including forecasting, imputation, detection, and classification. Paper: Large Pre-trained time series models for cross-domain Time series analysis tasks

Configuration Parameters

config = {
    "task_name": "forecasting",  # Options: "forecasting", "imputation", "detection", "classification"
    "forecast_horizon": 192,      # Number of timesteps to forecast
    "head_dropout": 0,            # Dropout rate for the forecasting head
    "weight_decay": 0,            # Weight decay for optimization
    "max_patch": 16,              # Maximum patch size
    "freeze_encoder": True,       # Freeze the patch embedding layer
    "freeze_embedder": True,      # Freeze the transformer encoder
    "freeze_head": False,         # The linear forecasting head must be trained
    "freeze_segment": True,       # Freeze the segmentation module
}

Loading the Model

from samay.model import LPTMModel

model = LPTMModel(config)
The model is automatically loaded from the kage08/lptm-large2 repository.

Loading Dataset

from samay.dataset import LPTMDataset

train_dataset = LPTMDataset(
    name="ett",
    datetime_col="date",
    path="./data/ETTh1.csv",
    mode="train",
    horizon=192,
)

val_dataset = LPTMDataset(
    name="ett",
    datetime_col="date",
    path="./data/ETTh1.csv",
    mode="test",
    horizon=192,
)

Zero-Shot Forecasting

LPTM supports zero-shot forecasting out of the box:
metrics, trues, preds, histories = model.evaluate(
    val_dataset,
    task_name="forecasting"
)

Fine-tuning

finetuned_model = model.finetune(
    train_dataset,
    task_name="forecasting"
)

Evaluation Metrics

LPTM supports comprehensive evaluation metrics:
metrics = model.evaluate(val_dataset, task_name="forecasting")
# Returns: {'mse': ..., 'mae': ..., 'mase': ..., 'mape': ..., 'rmse': ..., 'nrmse': ..., 'smape': ..., 'msis': ..., 'nd': ...}
LPTM requires specific data preprocessing. See the example notebook for more details.

Example Notebook

For a complete working example, see:

Build docs developers (and LLMs) love