Skip to main content

HybridTS

HybridTS Logo

Hybrid Time Series Forecasting with Prophet and Gradient Boosting

PyPI Python Tests License

HybridTS combines Prophet's trend and seasonality modeling with gradient boosting (XGBoost / LightGBM) to correct residuals — delivering more accurate forecasts than either model alone.

Quick Start • Installation • Examples • Contributing


Features

  • Hybrid forecasting: Prophet captures trend and seasonality; XGBoost or LightGBM corrects what Prophet misses.
  • sklearn-style API: fit(), predict(), and evaluate() — no new paradigms to learn.
  • Dependency injection: pass any configured model instance — no subclassing required.
  • Built-in evaluation: holdout-based evaluation with MAE, RMSE, MAPE, sMAPE, R² and bias, accessible as attributes after evaluate().
  • Integrated plotting: visualize forecasts and evaluation results with a single method call (requires matplotlib).
  • Auto feature engineering: holiday calendars, payday indicators, and calendar features generated automatically from the data range.

How It Works

┌─────────────────────────────┐
│       Input Data (ds, y)    │
└──────────────┬──────────────┘
               │
       ┌───────▼────────┐
       │  Primary Model  │
       │   (Prophet)     │
       │                 │
       │  trend +        │
       │  seasonality +  │
       │  holidays       │
       └───────┬─────────┘
               │
       ┌───────▼─────────────────┐
       │   Residual Calculation  │
       │   actual − ŷ_prophet    │
       └───────┬─────────────────┘
               │
       ┌───────▼────────────────────┐
       │     Residual Model          │
       │  (XGBoost / LightGBM)       │
       │                             │
       │  calendar + payday +        │
       │  holiday features           │
       └───────┬─────────────────────┘
               │
       ┌───────▼──────────────────────────┐
       │  Final Forecast                   │
       │  ŷ_prophet  +  ŷ_residual        │
       └───────────────────────────────────┘

Installation

pip install hybridts

Optional — plotting support:

pip install hybridts[plotting]

Quick Start

import pandas as pd
from hybridts import HybridForecaster, ProphetModel, XGBoostModel

# Configure models
prophet = ProphetModel(
    param_grid={"changepoint_prior_scale": [0.05, 0.1]},
    cv_params={"initial": "300 days", "period": "30 days", "horizon": "30 days"},
)
xgb = XGBoostModel(
    param_grid={"window_length": [21], "estimator__max_depth": [5, 7]},
    static_params={"n_estimators": 200, "max_depth": 5},
    regressor_params={"random_state": 42},
    cv_initial_window=270,
    cv_step_length=30,
    window_length=21,
    fh=30,
    strategy="recursive",
)

# Evaluate on holdout, then retrain on full data
forecaster = HybridForecaster(primary_model=prophet, secondary_model=xgb)
df = pd.read_csv("data.csv", parse_dates=["ds"])  # columns: ds, y

forecaster, metrics = forecaster.evaluate_and_fit(df)

# Forecast the next 30 days
forecast = forecaster.predict(horizon=30)
print(forecast)

# Visualize
forecaster.plot_forecast(df)
forecaster.plot_evaluation()

Forecast output:

Column Description
data Forecast date
forecast_primary_base Prophet baseline
residual_correction Gradient boosting adjustment
forecast_final Final hybrid forecast

Data Format

A pandas DataFrame with exactly two columns:

Column Type Description
ds datetime Date of observation
y float Value to forecast

Evaluation

metrics, y_true, y_pred = forecaster.evaluate(df)

# Metric reports available after evaluate()
forecaster.metrics_report_          # hybrid forecast
forecaster.primary_metrics_report_  # Prophet baseline alone

Available metrics: MAE, MSE, RMSE, MAPE, sMAPE, R-squared, Bias.


Examples

See the examples/ folder for notebooks covering common use cases.


Contributing

See CONTRIBUTING.md for development setup and contribution guidelines.


License

MIT — see LICENSE


Davi Franco — GitHub

⬆ Back to top

Release files for hybridts 0.5.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 hybridts 0.5.0
File Size Uploaded
hybridts-0.5.0.tar.gz 40.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hybridts 0.5.0
File Interpreter ABI Platform
hybridts-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 62.0 kB

Release files / hybridts-0.5.0.tar.gz

Download URL hybridts-0.5.0.tar.gz
Size 40.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9e17cefa0b4e02b00f7558d7c354888b0a32de392f14507d939caf5ebe538fb7
BLAKE2b-256 checksum
How to use checksums
58a26bdf1e1f0e4394abbc7ce71baea83bc26f437b294686479cdd400fda209c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / hybridts-0.5.0-py3-none-any.whl

Download URL hybridts-0.5.0-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e203199a022c9feeed1cfbae534e1f298e1c023113684bce9a3392e568f1d5b
BLAKE2b-256 checksum
How to use checksums
ce0a080a701c7cb9dd3d6644dcadd375856463342a8df0d1a2e6806200ecee28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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