Skip to main content

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

Project description

RollingCV Logo

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-0.1.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-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rollingcv-0.1.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-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9458764cccb605b7c14d198d4c689573c4c636c2196f43ecdc812e1ef53d0ff9
MD5 fd4d6499cd1206ed0c4bced7a556e7e0
BLAKE2b-256 7045fd2a72e022ae8f880732e3228ba3596544917300dc14dca4ac3605fed0ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rollingcv-0.1.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-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b5474507595c7cb0ba18baa9330317baaf46230625ffb36c68bc2d49347aa07
MD5 58adacb851fa321426e663ec59968fbb
BLAKE2b-256 ec3559843707f20d4715103eb4f328742429378ebb1d6cf4c7b021aa730751fd

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