Time-Series-Library Classification
Use this skill after ts-classification-data-prep. THUML Time-Series-Library (TSLib) is best when the user wants to run deep learning classification experiments with the repository's unified run.py, UEA .ts datasets, PyTorch models, official bash recipes, checkpoints, and reproducible benchmark-style runs.
Do not present TSLib as a general sklearn-style classifier library. It is a research codebase: training is driven by CLI scripts, native output is accuracy, and many conveniences such as sklearn fit/predict objects, built-in stratified CV, and calibration reports are not documented.
Minimum Install
git clone https://github.com/thuml/Time-Series-Library.git
cd Time-Series-Library
conda create -n tslib python=3.11
conda activate tslib
pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
Install optional model dependencies only when needed, especially mamba_ssm for Mamba/MambaSL on Linux/CUDA.
Data Contract
- Require a completed
ts-classification-data-prep contract: dataset name, TRAIN/TEST split, labels, class balance, channels/features, maximum sequence length, padding/truncation policy, missing-value policy, and leakage notes.
- Use official UEA layout:
--data UEA, --root_path ./dataset/<DatasetName>/, --model_id <DatasetName>, with <DatasetName>_TRAIN.ts and <DatasetName>_TEST.ts.
- The loader uses
sktime.datasets.load_from_tsfile_to_dataframe(..., replace_missing_vals_with='NaN'), converts labels to integer class codes, interpolates missing values, normalizes features, and pads/clips batches through collate_fn.
- Runtime tensors are
(batch_size, padded_length, feature_dim) plus padding_mask; this is not sklearn/sktime numpy3D.
- For unequal length, TSLib sets
seq_len to the max train/test length and uses padding masks; if dimensions inside one sample have different length, the loader subsamples long series.
Read references/tslib-classification-data.md before adapting data, using variable length, changing normalization, or adding custom splits.
Model Selection
Use --task_name classification and an official model name. Source-supported classification models include:
Autoformer, Crossformer, DLinear, ETSformer, FEDformer, FiLM, Informer, LightTS, MICN, MSGNet, MambaSingleLayer, Nonstationary_Transformer, PatchTST, Pyraformer, Reformer, SegRNN, TimeFilter, TimeMixer, TimesNet, Transformer, and iTransformer.
Official bash scripts exist for a smaller set: Autoformer, Crossformer, DLinear, ETSformer, FEDformer, FiLM, Informer, LightTS, MICN, MambaSL (--model MambaSingleLayer), PatchTST, Pyraformer, Reformer, TimesNet, Transformer, and iTransformer.
Read references/tslib-classification-models.md before claiming support for models without classification scripts or models that raise NotImplementedError.
Training And Prediction Pattern
python -u run.py \
--task_name classification \
--is_training 1 \
--root_path ./dataset/Heartbeat/ \
--model_id Heartbeat \
--model TimesNet \
--data UEA \
--e_layers 3 \
--batch_size 16 \
--d_model 16 \
--d_ff 32 \
--top_k 1 \
--des Exp \
--itr 1 \
--learning_rate 0.001 \
--train_epochs 30 \
--patience 10
Exp_Classification trains with RAdam, CrossEntropyLoss, gradient clipping, early stopping on validation accuracy, and saves checkpoint.pth. Test mode uses --is_training 0 and loads the matching checkpoint.
TSLib does not expose a documented sklearn-like predict_proba. Internally it computes softmax(logits) then argmax; use custom code around Exp_Classification.test if calibrated probabilities, ROC-AUC, or exported predictions are required.
Evaluation
- Native metric: accuracy via
cal_accuracy.
- For balanced classes, report accuracy plus optional external macro/weighted F1 from saved logits/predictions.
- For imbalanced classes, add external
f1_macro, balanced accuracy, per-class recall/precision, confusion matrix, ROC-AUC/PR-AUC where probabilities are exported.
- TSLib does not document stratified cross-validation. To use stratified CV, create fold-specific UEA TRAIN/TEST directories outside the repo workflow, keep every preprocessing step inside each fold, and run one script per fold.
Anti-Leakage Rules
- Split TRAIN/TEST before normalization, interpolation choices, augmentation, padding/truncation tuning, and any external feature engineering.
- Fit scalers/normalizers only on TRAIN for each fold. The stock
UEAloader normalizes each loaded split independently; if strict train-fitted scaling is required, modify the loader deliberately and document it.
- Use augmentation only on TRAIN; the official loader checks
flag == "TRAIN" before applying augmentation.
- Do not compute max sequence length, class mapping, or missing-value policies from a held-out final test set unless that metadata is part of a fixed public benchmark contract.
- Use stratified folds when you create custom CV for imbalanced classes; preserve subject/device groups if present.
Common Errors
- Passing arrays directly instead of UEA
.ts files and --data UEA.
- Mismatching
--root_path, --model_id, and filenames; the loader expects <model_id>_TRAIN.ts or <model_id>_TEST.ts.
- Treating
--seq_len like a user-chosen fixed window; classification resets it from max train/test sequence length during model build.
- Expecting native
fit, predict, or predict_proba methods.
- Using models present in
models/ that explicitly do not support classification, such as KANAD, MultiPatchFormer, TiDE, WPMixer, or forecast-only Mamba variants.
- Reading validation/test accuracy printed during training as a leak-free benchmark without checking the experiment split design.
References
- Read
references/tslib-classification-models.md for supported models, script coverage, and model limitations.
- Read
references/tslib-classification-data.md for UEA .ts format, tensor shapes, padding, normalization, CV, and metrics.
- Read
references/official-sources.md for official sources consulted.
- Use
scripts/validate_uea_ts_split.py to check required TRAIN/TEST .ts files before running TSLib.
Ready Checklist
ts-classification-data-prep contract is complete and leakage risks are documented.
- Dataset directory has
<DatasetName>_TRAIN.ts and <DatasetName>_TEST.ts.
- Labels/classes, channel count, sequence lengths, missing values, and imbalance are checked.
- Model name is source-supported for
task_name=classification and required dependencies are installed.
- TRAIN-only preprocessing, augmentation, and fold generation are enforced.
- Accuracy plus imbalance-aware external metrics are reported on held-out folds/test data.
1---2name: classification-time-series-library3description: Use THUML Time-Series-Library/TSLib for deep learning time-series classification after ts-classification-data-prep, including UEA .ts TRAIN/TEST files, UEAloader, variable-length padding masks, multivariate channels, task_name=classification, CrossEntropyLoss training, softmax probabilities, accuracy evaluation, official classification scripts, supported model names such as TimesNet, Transformer, Autoformer, PatchTST, iTransformer, MambaSingleLayer/MambaSL, TimeMixer, and strict anti-leakage preprocessing.4---56# Time-Series-Library Classification78Use this skill after `ts-classification-data-prep`. THUML Time-Series-Library (TSLib) is best when the user wants to run deep learning classification experiments with the repository's unified `run.py`, UEA `.ts` datasets, PyTorch models, official bash recipes, checkpoints, and reproducible benchmark-style runs.910Do not present TSLib as a general sklearn-style classifier library. It is a research codebase: training is driven by CLI scripts, native output is accuracy, and many conveniences such as sklearn `fit/predict` objects, built-in stratified CV, and calibration reports are not documented.1112## Minimum Install1314```bash15git clone https://github.com/thuml/Time-Series-Library.git16cd Time-Series-Library17conda create -n tslib python=3.1118conda activate tslib19pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cu12120pip install -r requirements.txt21```2223Install optional model dependencies only when needed, especially `mamba_ssm` for Mamba/MambaSL on Linux/CUDA.2425## Data Contract2627- Require a completed `ts-classification-data-prep` contract: dataset name, TRAIN/TEST split, labels, class balance, channels/features, maximum sequence length, padding/truncation policy, missing-value policy, and leakage notes.28- Use official UEA layout: `--data UEA`, `--root_path ./dataset/<DatasetName>/`, `--model_id <DatasetName>`, with `<DatasetName>_TRAIN.ts` and `<DatasetName>_TEST.ts`.29- The loader uses `sktime.datasets.load_from_tsfile_to_dataframe(..., replace_missing_vals_with='NaN')`, converts labels to integer class codes, interpolates missing values, normalizes features, and pads/clips batches through `collate_fn`.30- Runtime tensors are `(batch_size, padded_length, feature_dim)` plus `padding_mask`; this is not sklearn/sktime `numpy3D`.31- For unequal length, TSLib sets `seq_len` to the max train/test length and uses padding masks; if dimensions inside one sample have different length, the loader subsamples long series.3233Read `references/tslib-classification-data.md` before adapting data, using variable length, changing normalization, or adding custom splits.3435## Model Selection3637Use `--task_name classification` and an official model name. Source-supported classification models include:3839`Autoformer`, `Crossformer`, `DLinear`, `ETSformer`, `FEDformer`, `FiLM`, `Informer`, `LightTS`, `MICN`, `MSGNet`, `MambaSingleLayer`, `Nonstationary_Transformer`, `PatchTST`, `Pyraformer`, `Reformer`, `SegRNN`, `TimeFilter`, `TimeMixer`, `TimesNet`, `Transformer`, and `iTransformer`.4041Official bash scripts exist for a smaller set: `Autoformer`, `Crossformer`, `DLinear`, `ETSformer`, `FEDformer`, `FiLM`, `Informer`, `LightTS`, `MICN`, `MambaSL` (`--model MambaSingleLayer`), `PatchTST`, `Pyraformer`, `Reformer`, `TimesNet`, `Transformer`, and `iTransformer`.4243Read `references/tslib-classification-models.md` before claiming support for models without classification scripts or models that raise `NotImplementedError`.4445## Training And Prediction Pattern4647```bash48python -u run.py \49 --task_name classification \50 --is_training 1 \51 --root_path ./dataset/Heartbeat/ \52 --model_id Heartbeat \53 --model TimesNet \54 --data UEA \55 --e_layers 3 \56 --batch_size 16 \57 --d_model 16 \58 --d_ff 32 \59 --top_k 1 \60 --des Exp \61 --itr 1 \62 --learning_rate 0.001 \63 --train_epochs 30 \64 --patience 1065```6667`Exp_Classification` trains with `RAdam`, `CrossEntropyLoss`, gradient clipping, early stopping on validation accuracy, and saves `checkpoint.pth`. Test mode uses `--is_training 0` and loads the matching checkpoint.6869TSLib does not expose a documented sklearn-like `predict_proba`. Internally it computes `softmax(logits)` then `argmax`; use custom code around `Exp_Classification.test` if calibrated probabilities, ROC-AUC, or exported predictions are required.7071## Evaluation7273- Native metric: accuracy via `cal_accuracy`.74- For balanced classes, report accuracy plus optional external macro/weighted F1 from saved logits/predictions.75- For imbalanced classes, add external `f1_macro`, balanced accuracy, per-class recall/precision, confusion matrix, ROC-AUC/PR-AUC where probabilities are exported.76- TSLib does not document stratified cross-validation. To use stratified CV, create fold-specific UEA TRAIN/TEST directories outside the repo workflow, keep every preprocessing step inside each fold, and run one script per fold.7778## Anti-Leakage Rules7980- Split TRAIN/TEST before normalization, interpolation choices, augmentation, padding/truncation tuning, and any external feature engineering.81- Fit scalers/normalizers only on TRAIN for each fold. The stock `UEAloader` normalizes each loaded split independently; if strict train-fitted scaling is required, modify the loader deliberately and document it.82- Use augmentation only on TRAIN; the official loader checks `flag == "TRAIN"` before applying augmentation.83- Do not compute max sequence length, class mapping, or missing-value policies from a held-out final test set unless that metadata is part of a fixed public benchmark contract.84- Use stratified folds when you create custom CV for imbalanced classes; preserve subject/device groups if present.8586## Common Errors8788- Passing arrays directly instead of UEA `.ts` files and `--data UEA`.89- Mismatching `--root_path`, `--model_id`, and filenames; the loader expects `<model_id>_TRAIN.ts` or `<model_id>_TEST.ts`.90- Treating `--seq_len` like a user-chosen fixed window; classification resets it from max train/test sequence length during model build.91- Expecting native `fit`, `predict`, or `predict_proba` methods.92- Using models present in `models/` that explicitly do not support classification, such as `KANAD`, `MultiPatchFormer`, `TiDE`, `WPMixer`, or forecast-only Mamba variants.93- Reading validation/test accuracy printed during training as a leak-free benchmark without checking the experiment split design.9495## References9697- Read `references/tslib-classification-models.md` for supported models, script coverage, and model limitations.98- Read `references/tslib-classification-data.md` for UEA `.ts` format, tensor shapes, padding, normalization, CV, and metrics.99- Read `references/official-sources.md` for official sources consulted.100- Use `scripts/validate_uea_ts_split.py` to check required TRAIN/TEST `.ts` files before running TSLib.101102## Ready Checklist103104- `ts-classification-data-prep` contract is complete and leakage risks are documented.105- Dataset directory has `<DatasetName>_TRAIN.ts` and `<DatasetName>_TEST.ts`.106- Labels/classes, channel count, sequence lengths, missing values, and imbalance are checked.107- Model name is source-supported for `task_name=classification` and required dependencies are installed.108- TRAIN-only preprocessing, augmentation, and fold generation are enforced.109- Accuracy plus imbalance-aware external metrics are reported on held-out folds/test data.