Skip to main content

Lightweight validation framework for time series forecasting.

Project description

timeframes logo

A lightweight framework for time series validation, backtesting, and visualization.
Timeframes provides simple and efficient tools for splitting, validating, and evaluating forecasting models — without unnecessary dependencies or boilerplate.


🧠 Need help?

Try TimeframesGPT
a specialized assistant trained on the full Timeframes codices.


Installation

pip install timeframes

Quick Example

import timeframes as ts
from sklearn.linear_model import LinearRegression

# Load example data
df = ts.load_example("air_passengers")  # or "ts_components", "ts_components_complex"

# Split into train, validation, and test
train, val, test = ts.split(df, ratios=(0.7, 0.2, 0.1))

# Validate using walk-forward cross-validation
model = LinearRegression()
report, (y_true, y_pred) = ts.validate(
    model, df, target_col="AirPassengers", method="walkforward", mode="expanding", folds=5, return_preds=True
)

print(report)
# {'mae': 0.213, 'rmse': 0.322, 'smape': 3.9}

# Visualize forecast results
ts.plot_forecast(y_true, y_pred, title="Walk-Forward Forecast", show_residuals=True)
example

💡 You can list all built-in datasets with ts.list_examples().


✨ Features

  • Minimal — depends only on NumPy and pandas.
  • Consistent — unified API for all validation methods.
  • Flexible — works with any model exposing .fit() / .predict().
  • Visual — built-in plot_forecast() with datetime alignment and residuals.
  • Transparent — every function returns clear, reproducible outputs.

🧩 Supported Methods

Function Description
ts.split() Single train/validation/test split
ts.validate() Cross-validation (walk-forward or temporal K-Fold)
ts.backtest() Out-of-sample testing
ts.evaluate() Metric evaluation (MAE, RMSE, sMAPE, rMAE)

📂 Examples

Timeframes includes several runnable demonstrations for validation, backtesting, and visualization:

Script Description
examples/forecasts.py Full workflow: validation + backtest + plots
examples/kfold_demo.py Temporal K-Fold cross-validation
examples/visualize_splits_demo.py Visualize expanding, moving, and K-Fold splits

Run any example directly:

python examples/forecasts.py

Or run all __main__ demos automatically (via pytest):

pytest

This executes every example and internal demonstration, ensuring reproducibility across releases.


🧠 Built-in Datasets

Name Description Period Source
air_passengers Classic airline passenger dataset 1949–1960 Public domain (Box & Jenkins, 1976)
ts_components Synthetic trend + seasonality decomposition 2000–2011 Generated (Andrew R. Garcia, 2025)
ts_components_complex Nonlinear trend + multi-frequency seasonality 2000–2011 Generated (Andrew R. Garcia, 2025)

Load with:

df = ts.load_example("ts_components")

List all available datasets:

ts.list_examples()

📈 Visualization Example

ts.plot_forecast(
    y_true, 
    y_pred, 
    title="Out-of-Sample Forecast", 
    show_residuals=True
)

Generates a clean, publication-ready figure with automatic datetime indexing and optional residual bars.


License

MIT License © 2025 Andrew R. Garcia

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

timeframes-1.3.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

timeframes-1.3.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file timeframes-1.3.0.tar.gz.

File metadata

  • Download URL: timeframes-1.3.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for timeframes-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7c38db8943092ebe90ae80d4846a2c5a384bf0d03a0479df8ae09684a3746de8
MD5 24c213f27434b1f089e53050c546df76
BLAKE2b-256 3135208900e327d1575c25c2d86c4b0bd1bd491da32bdd693fd3deede6134b85

See more details on using hashes here.

File details

Details for the file timeframes-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: timeframes-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for timeframes-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebbe866a913fcc450019d2929dd89db4518db15e1733f35abeb2437fc1c32157
MD5 0897e8af83c893843bb5bee1f9fbfb2e
BLAKE2b-256 f2f458cf39366c19dda3531bc4bbeb9d8d8764c55bc6195e56d7846912f62616

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