Automated TFT modeling with publication-ready report generation
Project description
TFT Report Generator
Automated Temporal Fusion Transformer modeling with publication-ready report generation.
Features
- Automatic Data Analysis: EDA with GPT-powered insights
- TFT Architecture Visualization: Model structure diagram with hyperparameters
- Model Training: Automated training with progress tracking
- Bootstrap Significance Testing: Parameter stability analysis
- Variable Importance Analysis: SHAP-like interpretability
- Prediction Visualization: Actual vs Predicted with uncertainty bands
- Word Document Report: Complete academic-style report
Installation
pip install git+https://github.com/sdkparkforbi/tft-report.git
Requirements
Minimum System Requirements
| Component | Requirement |
|---|---|
| Python | >= 3.9 |
| RAM | >= 8 GB (16 GB recommended) |
| GPU | Optional (CPU works, GPU faster) |
| Storage | >= 2 GB free space |
Dependencies
pytorch>=2.0.0
pytorch-forecasting>=1.0.0
lightning>=2.0.0
pandas>=1.5.0
numpy>=1.21.0
matplotlib>=3.5.0
python-docx>=0.8.0
openai>=1.0.0
API Keys
- OpenAI API Key: Required for GPT-powered explanations
- Set as environment variable:
OPENAI_API_KEY - Or pass directly:
api_key='your-key' - Colab: Store in Secrets as
OPENAI_API_KEY
- Set as environment variable:
Quick Start
Google Colab (Recommended)
# Install
!pip install git+https://github.com/sdkparkforbi/tft-report.git -q
# Import
from tft_report import generate_tft_report
import pandas as pd
import numpy as np
# Sample data
np.random.seed(42)
n_patients, n_days = 5, 60
df = pd.DataFrame({
'time_idx': np.tile(range(n_days), n_patients),
'patient': np.repeat([f'P{i}' for i in range(n_patients)], n_days),
'glucose': np.random.normal(140, 20, n_patients * n_days),
'insulin': np.random.randint(8, 16, n_patients * n_days),
'dayofweek': np.tile(np.arange(n_days) % 7, n_patients),
})
# Generate report
generate_tft_report(
df,
target='glucose',
group_id='patient',
time_idx='time_idx',
known_reals=['insulin', 'dayofweek'],
download=True
)
Local Python
from tft_report import generate_tft_report
import pandas as pd
df = pd.read_csv('your_data.csv')
generate_tft_report(
df,
target='glucose',
group_id='patient',
time_idx='time_idx',
api_key='your-openai-api-key'
)
Configuration
generate_tft_report(
df,
target='glucose',
group_id='patient',
time_idx='time_idx',
known_reals=['insulin', 'dayofweek'], # Known future variables
unknown_reals=['glucose'], # Unknown future variables
static_categoricals=['patient'], # Static categorical variables
config={
'max_encoder_length': 14, # Lookback window
'max_prediction_length': 3, # Forecast horizon
'hidden_size': 32, # Model hidden size
'attention_head_size': 2, # Number of attention heads
'lstm_layers': 2, # Number of LSTM layers
'dropout': 0.1, # Dropout rate
'batch_size': 32, # Training batch size
'max_epochs': 50, # Maximum training epochs
'n_bootstrap': 100, # Bootstrap iterations
},
verbose=True,
download=True
)
Data Format
Your DataFrame must have:
| Column | Description | Example |
|---|---|---|
time_idx |
Integer time index | 0, 1, 2, ... |
group_id |
Group identifier | 'P0', 'P1', ... |
target |
Target variable to predict | glucose values |
| Other columns | Covariates | insulin, dayofweek |
Example Data Structure
time_idx patient glucose insulin dayofweek
0 0 P0 145.23 10 0
1 1 P0 138.45 12 1
2 2 P0 142.67 11 2
...
Output
The generated zip file contains:
-
Word Document (
tft_analysis_report.docx)- Introduction
- Data Description with tables and figures
- Model Specification (architecture, hyperparameters)
- Results (performance metrics, variable importance)
- Bootstrap significance analysis
- Conclusion
-
Figures (PNG, 300 DPI)
- Target distribution histogram
- Time series plots
- TFT architecture diagram
- Prediction vs Actual scatter
- Uncertainty visualization
- Variable importance bar chart
- Attention weights (if available)
Report Structure
1. Introduction
- Dataset overview
- TFT methodology rationale
2. Data Description
- Table 1: Dataset characteristics
- Figure 1: Target distribution
- Figure 2: Time series by group
3. Model Specification
- 3.1 TFT Architecture (with diagram)
- 3.2 Hyperparameters (Table 2)
4. Results
- 4.1 Model Performance (MAE, RMSE)
- 4.2 Variable Importance
- 4.3 Bootstrap Significance
5. Conclusion
GPU Acceleration
For faster training, use GPU:
Google Colab
- Runtime → Change runtime type → GPU
Local
import torch
print(f"GPU available: {torch.cuda.is_available()}")
Troubleshooting
"OpenAI API key not found"
# Option 1: Pass directly
generate_tft_report(df, ..., api_key='sk-...')
# Option 2: Environment variable
import os
os.environ['OPENAI_API_KEY'] = 'sk-...'
# Option 3: Colab Secrets
# Add OPENAI_API_KEY in Colab's Secrets (key icon)
"CUDA out of memory"
# Reduce batch size and model size
generate_tft_report(df, ..., config={
'batch_size': 16,
'hidden_size': 16,
'attention_head_size': 1
})
"Module not found"
pip install pytorch-forecasting lightning python-docx openai
License
MIT License
Citation
If you use this package in your research, please cite:
@software{tft_report,
title = {TFT Report Generator},
author = {Your Name},
year = {2025},
url = {https://github.com/sdkparkforbi/tft-report}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tft_report-1.0.0.tar.gz.
File metadata
- Download URL: tft_report-1.0.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
794791b6fdd9b4405cbe955eea3ef50799f26aec30b98e7744d125716e1ad693
|
|
| MD5 |
11099ece2d42c1032e49e6a6b9ed0874
|
|
| BLAKE2b-256 |
ba2cb2d1ffdf31182674c94922a23317ae5ad6653c4728a9be156bca34bfce6f
|
File details
Details for the file tft_report-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tft_report-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47bddba506766c5ae099cfbe77eed5f8fa7d093b705f836d907313852c7c7276
|
|
| MD5 |
ac00d477fc0121f6cc35e1f9464ba04f
|
|
| BLAKE2b-256 |
27bcea91c12272983343528a8459d136034b799cbcbb0454038be4633c565704
|