Welcome to TFTS (TensorFlow Time Series), a Python library for state-of-the-art deep learning time series analysis. TFTS provides production-ready implementations of cutting-edge models for forecasting, classification, and anomaly detection tasks.
TFTS simplifies time series modeling by providing:
- State-of-the-Art Models
- Access to 20+ pre-implemented deep learning architectures including Transformers, BERT, Informer, Autoformer, and more. All models are optimized for time series tasks and ready for production use.
- Unified API
- Consistent interface across all models through
AutoModelandAutoConfig. Switch between architectures with a single line of code while maintaining the same workflow. - Production Ready
- Built on TensorFlow 2.x with native support for distributed training, mixed precision, TPUs, and TensorFlow Serving. Export models to SavedModel or ONNX formats for deployment.
- Flexible Architecture
- Modular design allows easy customization of model components, training loops, and data pipelines. Integrate TFTS models as backbones in your custom architectures.
- Comprehensive Tasks
- Support for forecasting (univariate/multivariate), classification, anomaly detection, and segmentation tasks with task-specific model heads.
- 📈 Multiple Tasks
- Single/multi-step forecasting
- Probabilistic forecasting with uncertainty quantification
- Time series classification
- Anomaly detection
- Change point detection and segmentation
- 🚀 20+ Models
- Classic: RNN, LSTM, GRU, Seq2Seq
- CNN-based: TCN, WaveNet, UNet
- Transformer-based: Transformer, BERT, Informer, Autoformer, PatchTST, iTransformer
- Specialized: N-BEATS, DLinear, TFT, DeepAR, RWKV, Diffusion
- ⚡ Performance
- Multi-GPU training with
tf.distribute - TPU support for large-scale training
- Mixed precision training (FP16/BF16)
- TensorFlow data pipelines for efficient I/O
- Multi-GPU training with
- 🔧 Flexible
- Modular layer design for custom architectures
- Feature engineering utilities (lag features, rolling statistics, datetime features)
- Custom training loops and callbacks
- Integration with Keras ecosystem
Install TFTS using pip:
pip install tfts- Requirements:
- Python >= 3.7
- TensorFlow >= 2.4
For development installation:
git clone https://github.com/LongxingTan/Time-series-prediction.git
cd Time-series-prediction
pip install -e .Here's a minimal example to get started with TFTS:
import tensorflow as tf
import tfts
from tfts import AutoConfig, AutoModel, KerasTrainer
# 1. Load sample data
train_length = 24
predict_length = 8
train, valid = tfts.get_data('sine', train_length, predict_length)
# 2. Choose and configure a model
config = AutoConfig.for_model('transformer')
model = AutoModel.from_config(config, predict_sequence_length=predict_length)
# 3. Train the model
trainer = KerasTrainer(model)
trainer.train(train, valid, epochs=10)
# 4. Make predictions
predictions = trainer.predict(valid[0])TFTS provides implementations of state-of-the-art time series models:
- Transformer-Based Models
transformer: Standard Transformer architecture adapted for time seriesbert: BERT-style bidirectional encoder for representation learninginformer: ProbSparse self-attention for long sequence forecastingautoformer: Auto-correlation mechanism for decompositiontft: Temporal Fusion Transformer with interpretable attentionpatch_tst: Patch-based Transformer for efficient trainingitransformer: Inverted Transformer treating variates as tokens
- RNN-Based Models
rnn: Configurable RNN with LSTM/GRU cellsseq2seq: Encoder-decoder architecture with attentiondeep_ar: Probabilistic forecasting with autoregressive RNN
- CNN-Based Models
tcn: Temporal Convolutional Network with dilated convolutionswavenet: WaveNet-style architecture with causal convolutionsunet: U-Net style encoder-decoder for sequence-to-sequence
- Specialized Models
nbeats: Neural Basis Expansion Analysis for interpretable forecastingdlinear: Simple linear model with decompositionrwkv: RWKV architecture with linear attentiondiffusion: Diffusion-based probabilistic forecastingtide: Time-series Dense Encodergpt: GPT-style autoregressive model
.. toctree:: :maxdepth: 2 :caption: Getting Started installation tutorials
.. toctree:: :maxdepth: 2 :caption: User Guide models training
.. toctree:: :maxdepth: 2 :caption: Advanced Topics feature_engineering tricks
.. toctree:: :maxdepth: 2 :caption: API Reference api
.. toctree:: :maxdepth: 1 :caption: Additional Information examples faq
TFTS has been successfully used in production and competitions:
- Competition Wins
- Industry Use Cases
- Energy demand forecasting
- Financial time series prediction
- IoT sensor data analysis
- Weather and climate modeling
- Traffic flow prediction
Multi-variate Forecasting
import tensorflow as tf
from tfts import AutoConfig, AutoModel
# Configure for multi-variate input
config = AutoConfig.for_model('informer')
config.num_features = 10 # 10 input features
model = AutoModel.from_config(config, predict_sequence_length=24)
# Input: (batch, sequence_length, num_features)
x = tf.random.normal([32, 96, 10])
predictions = model(x) # Output: (32, 24, 1)Probabilistic Forecasting
from tfts import AutoConfig, AutoModel
# Use model with uncertainty quantification
config = AutoConfig.for_model('deep_ar')
model = AutoModel.from_config(config, predict_sequence_length=24)
# Get probabilistic predictions
predictions = model(x) # Returns distribution parametersCustom Feature Engineering
from tfts.data import TimeSeriesSequence
import pandas as pd
# Configure feature engineering
feature_config = {
'datetime': {
'type': 'datetime',
'features': ['hour', 'dayofweek', 'month'],
'time_col': 'timestamp'
},
'lags': {
'type': 'lag',
'columns': 'target',
'lags': [1, 2, 3, 7, 14]
},
'rolling': {
'type': 'rolling',
'columns': 'target',
'windows': [7, 14],
'functions': ['mean', 'std']
}
}
# Create data loader with automatic feature engineering
data_loader = TimeSeriesSequence(
data=df,
time_idx='timestamp',
target_column='target',
train_sequence_length=24,
predict_sequence_length=8,
feature_config=feature_config
)- Getting Help
- 📖 Read the documentation
- 💬 Ask questions in GitHub Discussions
- 🐛 Report bugs in GitHub Issues
- Contributing
- We welcome contributions! See our Contributing Guide for details.
If you use TFTS in your research, please cite:
@misc{tfts2020,
author = {Longxing Tan},
title = {TFTS: TensorFlow Time Series},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/longxingtan/time-series-prediction}},
}TFTS is released under the MIT License. See LICENSE for details.