HybridTS
Hybrid Time Series Forecasting with Prophet and Gradient Boosting
HybridTS combines Prophet's trend and seasonality modeling with gradient boosting (XGBoost / LightGBM) to correct residuals — delivering more accurate forecasts than either model alone.
Features
- Hybrid forecasting: Prophet captures trend and seasonality; XGBoost or LightGBM corrects what Prophet misses.
- sklearn-style API:
fit(),predict(), andevaluate()— 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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hybridts-0.5.0.tar.gz | 40.7 kB | Without provenance | Details for hybridts-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hybridts-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for hybridts-0.5.0-py3-none-any.whl |
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
|
Security for hybridts 0.5.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.