Skip to main content

Hybrid time series forecasting library combining Prophet with gradient boosting models

Project description

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 StartInstallationExamplesContributing


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 FrancoGitHub

⬆ Back to top

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

hybridts-0.5.0.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

hybridts-0.5.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file hybridts-0.5.0.tar.gz.

File metadata

  • Download URL: hybridts-0.5.0.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for hybridts-0.5.0.tar.gz
Algorithm Hash digest
SHA256 9e17cefa0b4e02b00f7558d7c354888b0a32de392f14507d939caf5ebe538fb7
MD5 5659ac5ebd1d52356afbdb031d81eac3
BLAKE2b-256 58a26bdf1e1f0e4394abbc7ce71baea83bc26f437b294686479cdd400fda209c

See more details on using hashes here.

File details

Details for the file hybridts-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: hybridts-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for hybridts-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e203199a022c9feeed1cfbae534e1f298e1c023113684bce9a3392e568f1d5b
MD5 5e50a6be248566f89fe4e44562cde150
BLAKE2b-256 ce0a080a701c7cb9dd3d6644dcadd375856463342a8df0d1a2e6806200ecee28

See more details on using hashes here.

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