Skip to main content

Forecasting Library Documentation

The forecastingLibrary is a unified, "zero-shot" forecasting framework designed to provide a seamless interface for multiple time-series forecasting architectures. It abstracts away the complexity of data preparation, feature engineering, and hyperparameter tuning.

Core Architecture

The library is built around an orchestration layer (UniversalForecaster) that delegates tasks to specific forecasting engines that all inherit from a common interface (BaseForecaster).

  • UniversalForecaster: The main entry point. It handles data validation, extensive automated feature engineering, train/test splitting for evaluation, and engine dispatch.
  • BaseForecaster: The abstract base class that defines the fit() and predict() contract for all engines.
  • Engines:
    • LinearForecaster: Wraps Nixtla's StatsForecast (AutoARIMA, AutoETS, AutoTheta, SeasonalNaive). Extremely fast and parallelized.
    • TreeEnsembleForecaster: A multi-output tree-based model using LightGBM wrapped in a RegressorChain. Uses shifted targets to predict the entire horizon in one shot without recursive loops.
    • TSFMForecaster: Wraps Hugging Face's Time Series Foundation Models (e.g., TinyTimeMixer) for deep learning-based forecasting.

Key Features

1. Auto-Testing & Model Selection (test_type)

The framework can automatically evaluate multiple configurations on a chronologically held-out 10% validation set, pick the best one using Mean Absolute Error (MAE), and seamlessly retrain on the 100% dataset.

  • test_type='model': Tests between different architectural families (e.g., linear vs tree_ensemble).
  • test_type='param': Tests different hyperparameter grids for a specific architecture (e.g., different n_estimators for tree_ensemble).

2. Automated Feature Engineering

When using non-linear models (like tree_ensemble), the UniversalForecaster automatically generates:

  • Cyclical Calendar Features: Sine/Cosine transformations of day-of-week, month, and hour.
  • Holiday Features: Automatic integration with holidays (currently configured for Indonesia).
  • Lag Features: Auto-scaled lag features based on the detected frequency (Daily, Weekly, Monthly, Hourly).
  • Rolling Statistics: Rolling mean and standard deviation (volatility) to capture recent trends.

Usage Guide

Initialization

from lib.forecastingLibrary.UniversalForecaster import UniversalForecaster

forecast = UniversalForecaster(
    input_windows=36,               # Lookback window (used primarily by TSFM)
    horizon=18,                     # The number of steps into the future to predict
    forecast_type='tree_ensemble',  # 'linear', 'tree_ensemble', 'tsfm' (or None to let test_type decide)
    test_type='model',              # 'model' to test architectures, 'param' to test hyperparameters
    tsfm_model_path="./local_ttm"   # Path to local foundation model weights (if using TSFM)
)

Data Format Requirements

The input data must be a Pandas DataFrame containing at minimum:

  • ds: The datetime column.
  • y: The numeric target variable to forecast.
  • unique_id (Optional): An identifier for multi-series forecasting. If omitted, the LinearForecaster will automatically inject a dummy ID.

Training & Predicting

# 1. Fit the forecaster. 
# If test_type is set, this will automatically hold out 10% of data, test, and retrain on 100%.
forecast.fit(df_train)

# 2. Predict the horizon
# Returns a DataFrame with an 'Ensemble' column containing the predictions
predictions_df = forecast.predict()

Adding New Engines

To add a new forecasting engine:

  1. Create a new class inheriting from BaseForecaster.
  2. Implement the fit(self, df) method. Ensure it does not modify the original df directly (use .copy()).
  3. Implement the predict(self) method to return a DataFrame containing at least an 'Ensemble' column.
  4. Add the new engine to the _available_forecast_types and _init_engine dispatch dictionary in UniversalForecaster.

Metadata

Release files for universal-forecasting-library 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for universal-forecasting-library 0.1.0
File Size Uploaded Provenance Actions
universal_forecasting_library-0.1.0.tar.gz 10.1 kB Without provenance Details for universal_forecasting_library-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for universal-forecasting-library 0.1.0
File Interpreter ABI Platform Actions
universal_forecasting_library-0.1.0-py3-none-any.whl Python 3 none any Details for universal_forecasting_library-0.1.0-py3-none-any.whl

Total release size: 19.9 kB

Release files / universal_forecasting_library-0.1.0.tar.gz

Download URL universal_forecasting_library-0.1.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3a98104ae7ffedaaee34b19915db7d2e1b6c38e9ed29d622466e984d889f6acc
BLAKE2b-256 checksum
How to use checksums
da8d88ccd5bc1fff631db06b1c2ce47a4d0896dcbe0f2a3e9a4311dd94c8172a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / universal_forecasting_library-0.1.0-py3-none-any.whl

Download URL universal_forecasting_library-0.1.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e46d6a18fe14b7f9b845f8875ef2f49ef3d9a7f439f40c6af9a7a7f2e1e253a
BLAKE2b-256 checksum
How to use checksums
54dfff057315c1e9b4d673e14f70f846eae817917945012773a93dbceecd5651
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for universal-forecasting-library 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page