TSCV: Time Series Cross-Validation
This repository is a scikit-learn extension for time series cross-validation. It introduces gaps between the training set and the test set, which mitigates the temporal dependence of time series and prevents information leakage.
Installation
pip install tscv
or
conda install -c conda-forge tscv
Usage
This extension defines 3 cross-validator classes and 1 function:
GapLeavePOutGapKFoldGapRollForwardgap_train_test_split
The three classes can all be passed, as the cv argument, to
scikit-learn functions such as cross-validate, cross_val_score,
and cross_val_predict, just like the native cross-validator classes.
The one function is an alternative to the train_test_split function in scikit-learn.
Examples
The following example uses GapKFold instead of KFold as the cross-validator.
import numpy as np
from sklearn import datasets
from sklearn import svm
from sklearn.model_selection import cross_val_score
from tscv import GapKFold
iris = datasets.load_iris()
clf = svm.SVC(kernel='linear', C=1)
# use GapKFold as the cross-validator
cv = GapKFold(n_splits=5, gap_before=5, gap_after=5)
scores = cross_val_score(clf, iris.data, iris.target, cv=cv)
The following example uses gap_train_test_split to split the data set into the training set and the test set.
import numpy as np
from tscv import gap_train_test_split
X, y = np.arange(20).reshape((10, 2)), np.arange(10)
X_train, X_test, y_train, y_test = gap_train_test_split(X, y, test_size=2, gap_size=2)
Contributing
- Report bugs in the issue tracker
- Express your use cases in the issue tracker
Documentations
Acknowledgments
- I would like to thank Jeffrey Racine and Christoph Bergmeir for the helpful discussion.
License
BSD-3-Clause
Citation
Wenjie Zheng. (2021). Time Series Cross-Validation (TSCV): an extension for scikit-learn. Zenodo. http://doi.org/10.5281/zenodo.4707309
@software{zheng_2021_4707309,
title={{Time Series Cross-Validation (TSCV): an extension for scikit-learn}},
author={Zheng, Wenjie},
month={april},
year={2021},
publisher={Zenodo},
doi={10.5281/zenodo.4707309},
url={http://doi.org/10.5281/zenodo.4707309}
}
Metadata
Release files for tscv 0.1.3
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 | |
|---|---|---|---|---|
| tscv-0.1.3.tar.gz | 13.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tscv-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.9 kB
Release files / tscv-0.1.3.tar.gz
| Download URL | tscv-0.1.3.tar.gz |
|---|---|
| Size | 13.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4934fcc9d5210d0bc4efcade76c195be2fb10bed82c827b05ac39953ef4dddc9
|
|
BLAKE2b-256 checksum How to use checksums |
cd5a7ebce6c6baa22f9fd4a6b87249d347c6339a1f5537279e03999fcf06b95c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / tscv-0.1.3-py3-none-any.whl
| Download URL | tscv-0.1.3-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8503ea18719b9891830dd436640990ccf4c5466307951454da9fd1a5a3243ce9
|
|
BLAKE2b-256 checksum How to use checksums |
65bdadaa4803a999efcb2feba16359cd6d7361a8edcdc26497a54ca796811392
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Security for tscv 0.1.3
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.