TimeGuard: Channel-wise Pool Training for Backdoor Defense in Time Series Forecasting
January 28, 2026 ยท View on GitHub
This repository provides code to (1) run TSF backdoor attacks to produce poisoned data, and (2) apply TimeGuard to defend against them.
Table of Contents
1. Prerequisites
-
Python 3.10+
-
Install dependencies:
pip install -r requirements.txt
2. Configuration
-
configs/default_config.yamlGlobal defaults (model, dataset, target pattern list, etc.) -
configs/attacks/*.yamlAttack configurations (hyperparameters, training details, poison rate, trigger settings, etc.) -
configs/timeguard/**/TimeGuard.yamlTimeGuard defense configurations per dataset / model / attack save folder results from attack methods
3. Run the Framework
3.1 Running Attacks
Train an attacker and generate a poisoned dataset (BackTime on PEMS03):
python attack_backtime_run.py \
--train_config_path configs/attacks/PEMS03_backtime_FEDformer_1212_attack.yaml
3.2 Running TimeGuard
Apply TimeGuard against a specified attack setting (example: defend against the above BackTime attack):
python defense_timeguard.py \
--defense_config_path configs/timeguard/PEMS03_backtime_FEDformer_1212/FEDformer/TimeGuard.yaml
4. Datasets
TimeGuard is validated on three real-world datasets and put it in under ./data folder:
- PEMS03 (Traffic flow)
Provided in the repository under
./data. - Weather (U.S. climate across locations) Download from Time-Series-Library: https://github.com/thuml/Time-Series-Library
- ETTm1 (Electricity transformer temperature / load series) Download from Time-Series-Library: https://github.com/thuml/Time-Series-Library
Acknowledgement
- BackTime: For its excellent work and repository, which this project builds on.
- Time-Series-Library: For TSF model implementations and dataset references.
- BackdoorBench and BackdoorBox: For baseline defense implementation details and references.