Skip to main content

Point and probabilistic time series forecasting — one interface, every model.

Project description

Twiga Forecast

Point & probabilistic time series forecasting — one interface, every model.

"Twiga" means giraffe in Swahili 🦒

Python PyPI License Ruff uv

Documentation · Tutorials · API Reference · PyPI


Most forecasting libraries force a choice — ML or deep learning, point forecasts or probabilistic ones, flexibility or production readiness. Twiga removes that trade-off.

A single TwigaForecaster trains, tunes, evaluates and backtests gradient-boosted trees, neural networks, quantile regression, parametric distributions and conformal prediction through one consistent, config-driven API.


Installation

# Core (tree models + lets-plot + great-tables)
pip install twiga

# + Matplotlib, Plotly, SciencePlots
pip install "twiga[plots]"

# + Neural networks (PyTorch Lightning)
pip install "twiga[nn]"

# Everything
pip install "twiga[all]"

Batteries included — XGBoost, LightGBM, CatBoost, NGBoost, lets-plot and Great Tables ship with the base install.

Extra What it adds
plots Matplotlib, Plotly, SciencePlots (publication-quality & interactive charts)
nn PyTorch, Lightning, TorchMetrics, TensorBoard
explain SHAP feature attribution
mlops MLflow, FastAPI, Evidently, Prefect
all Everything above

GPU (CUDA) support for neural networks

The default twiga[nn] install pulls the CPU-only PyTorch wheel from PyPI. To use a GPU, point your installer at the PyTorch CUDA index instead:

# pip
pip install "twiga[nn]" --extra-index-url https://download.pytorch.org/whl/cu124

# uv  (--index-strategy required so uv falls back to PyPI for non-torch packages)
uv pip install "twiga[nn]" \
  --extra-index-url https://download.pytorch.org/whl/cu124 \
  --index-strategy unsafe-best-match

Replace cu124 with the suffix that matches your driver:

CUDA version Suffix
11.8 cu118
12.1 cu121
12.4 cu124
12.6 cu126

Run nvidia-smi to check your CUDA version.


What Twiga offers

Feature Description
🔀 One interface, every model Swap a gradient-boosted tree for a neural network by changing one config object, not rewriting code
📊 Probabilistic forecasting Quantile regression, parametric distributions (Normal, Laplace, LogNormal, Gamma, Beta, Student-t) and conformal prediction, all composable with any backbone
🎯 Calibrated uncertainty Conformal prediction wraps any trained model with finite-sample coverage guarantees, no retraining required
⚙️ Experiment-ready Pydantic configs wired directly to Optuna search spaces; time-based backtesting and checkpoint-based resume are first-class features
🔍 Feature intelligence Eight association measures fused with Borda-count rank aggregation; stationarity tests, entropy and residual diagnostics in one call
🚀 Production MLOps Optional stack with experiment tracking, versioned checkpoints, drift monitoring, REST API and automated retraining

Quick start

import pandas as pd
from twiga.forecaster.core import TwigaForecaster
from twiga.core.config import DataPipelineConfig, ForecasterConfig
from twiga.models.ml.lightgbm_model import LIGHTGBMConfig

# train_df / test_df are pandas DataFrames with a DatetimeIndex
forecaster = TwigaForecaster(
    data_params=DataPipelineConfig(target_feature="load_mw", forecast_horizon=48),
    model_params=[LIGHTGBMConfig()],
    train_params=ForecasterConfig(split_freq="days", train_size=14, test_size=7),
)
forecaster.fit(train_df=train_df)
predictions_df, metrics_df = forecaster.evaluate_point_forecast(test_df=test_df)

Switch to a neural network by swapping one config:

from twiga.models.nn.mlpgam_model import MLPGAMConfig

forecaster = TwigaForecaster(
    data_params=DataPipelineConfig(target_feature="load_mw", forecast_horizon=48),
    model_params=[MLPGAMConfig()],
    train_params=ForecasterConfig(split_freq="days", train_size=14, test_size=7),
)

See the tutorials for probabilistic forecasting, conformal prediction, backtesting, HPO, and MLOps examples.


Documentation

Section Description
Get Started Install, key concepts, and your first forecast
User Guide Forecaster API, data pipeline, metrics, backtesting
Models ML tree models, neural networks, HPO
Probabilistic Distributions, quantile regression, conformal prediction
Tutorials End-to-end Jupyter notebooks
MLOps Tracking, serving, monitoring, orchestration
API Reference Full API reference

Contributing

Bug reports and feature requests are welcome — please open an issue. Pull requests should target the main branch and pass the pre-commit checks (uv run pre-commit run --all-files).


Contributors

Thanks goes to these wonderful people:

Anthony Faustine
Anthony Faustine
Frederick Apina
Frederick Apina
Lucas Pereira
Lucas Pereira

References

  1. A. Faustine, N. J. Nunes and L. Pereira, "Efficiency through Simplicity: MLP-based Approach for Net-Load Forecasting with Uncertainty Estimates," IEEE Transactions on Power Systems, doi: 10.1109/TPWRS.2024.3400123.
  2. A. Faustine and L. Pereira, "FPSeq2Q: Fully Parameterized Sequence to Quantile Regression for Net-Load Forecasting With Uncertainty Estimates," IEEE Transactions on Smart Grid, vol. 13, no. 3, pp. 2440-2451, May 2022, doi: 10.1109/TSG.2022.3148699.
  3. A. Faustine and L. Pereira, "Conformal Multilayer Perceptron-Based Probabilistic Net-Load Forecasting for Low-Voltage Distribution Systems with Photovoltaic Generation," 2024 IEEE International Conference on Communications, Control, and Computing Technologies for Smart Grids (SmartGridComm), Oslo, Norway, 2024, pp. 59-64, doi: 10.1109/SmartGridComm60555.2024.10738106.
  4. A. Faustine and L. Pereira, "Enhancing LV System Resilience through Probabilistic Forecasting of Interdependent Variables: Voltage, Reactive and Active Power," CIRED Chicago Workshop 2024: Resilience of Electric Distribution Systems, Chicago, USA, 2025, pp. 27-31, doi: 10.1049/icp.2024.2555.

Apache 2.0 License · Built with ❤️ for energy & power systems forecasting

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twiga-1.0.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twiga-1.0.0-py3-none-any.whl (714.6 kB view details)

Uploaded Python 3

File details

Details for the file twiga-1.0.0.tar.gz.

File metadata

  • Download URL: twiga-1.0.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for twiga-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b9db03ad97ffc8c3fc4c865e9fd006d1d0c54e7bbe3ce8148479799191a049b7
MD5 b6556b143065fb1f916c76c4660c9fe3
BLAKE2b-256 5a0f6d526bbbcc66c2d4587d58a5889b61ff40e818779dc511c4274b8772cd91

See more details on using hashes here.

Provenance

The following attestation bundles were made for twiga-1.0.0.tar.gz:

Publisher: publish_pypi.yaml on sambaiga/twiga-forecast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file twiga-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: twiga-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 714.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for twiga-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a48618d2c6ab49608616a83024be4a3de5a62b39a526e2fa658031c478170789
MD5 79901870becccc557e06a98e3ea303a9
BLAKE2b-256 7bc5d3ec5fbb1fab4a02e2cb04eb0f4fdecc8d65ebf42acd33d482fa622ed26d

See more details on using hashes here.

Provenance

The following attestation bundles were made for twiga-1.0.0-py3-none-any.whl:

Publisher: publish_pypi.yaml on sambaiga/twiga-forecast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page