Skip to main content

Fixed-window cross-validation for time series (scikit-learn compatible)

Project description

RollingWindowSplit

A smarter, production-ready alternative to scikit-learn's TimeSeriesSplit.

Perform rolling window cross-validation with fixed-size training sets and forecast horizons. Fully compatible with scikit-learn pipelines and supports percent-based sizes, configurable gaps, and clean fold visualization — even without matplotlib.


🚀 Why RollingWindowSplit?

When you use TimeSeriesSplit, each fold has a larger training set than the previous. That means:

  • You're training different models on different data sizes in each fold
  • You're not properly evaluating the model you plan to deploy
  • You're not reproducing the same model k times

With RollingWindowSplit, you:

  • ✅ Fix the training window size (just like in production)
  • ✅ Fix the forecast horizon (true out-of-sample evaluation)
  • ✅ Optionally add a gap to avoid data leakage
  • ✅ Run folds that actually replicate your deployment logic

📦 Installation

Install via pip:

pip install rollingcv

Or install locally for development:

pip install -e .

💡 Example

import numpy as np
from rollingcv import RollingWindowSplit

data = np.arange(1000)

rws = RollingWindowSplit(n_splits=5, window_size=0.6, horizon=0.1, gap=5)

# Show a text preview of the folds
rws.preview(data, style='default')

# Show a bar-style fold preview in console
rws.preview(data, style='bar')

🔍 Console Preview (Bar Style)

RollingWindowSplit Visual Preview (width=80):

Fold  1: ====================-----                    
Fold  2:   ====================-----                  
Fold  3:     ====================-----                
Fold  4:       ====================-----              
Fold  5:         ====================-----            

🧠 Key Features

  • ✅ Fixed or percent-based window and horizon sizes
  • ✅ Optional gap to simulate production delays
  • ✅ Clean __repr__ for logging/debugging
  • ✅ Compatible with scikit-learn pipelines
  • ✅ Console previews — no matplotlib required

🛡️ Error Handling

RollingWindowSplit protects against common pitfalls:

  • n_splits must be at least 2
  • window_size, horizon, and gap must be non-negative
  • Float sizes must be between 0 and 1
  • Raises a friendly message if there's not enough data to split

🧪 Testing

Run the built-in unit tests with:

pytest tests/

📄 License

MIT License. Use it, modify it, love it.


✨ Contribute

Pull requests welcome! Fork it, play with it, and if you improve it — share it back!


🙌 Credits

Created with care by marianotir

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

rollingcv-1.0.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

rollingcv-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file rollingcv-1.0.0.tar.gz.

File metadata

  • Download URL: rollingcv-1.0.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for rollingcv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 77d43641a1c77a4b05f7dad654d52c70ccba72bb37eb4e3b75a94638aa8a4180
MD5 0e114b552fb34af0810bc68e32715c32
BLAKE2b-256 c6467ba5158fe527d86be37c17f351cfccee8dbffff989bd73a5164d0bc21561

See more details on using hashes here.

File details

Details for the file rollingcv-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rollingcv-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for rollingcv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bad06e148e270887eaec74ca6315c8b83e0caa01b9ca61c0cdbc820dd123d503
MD5 41d22e29d8baab3bb6885ed0dfa2defa
BLAKE2b-256 6e9af997a7a37574a453366f3cc0e7c70f18b38e2d1427c91f846ffcbbd62a3a

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