pub struct TimeSeriesSplit { /* private fields */ }Expand description
Time-series cross-validation (rolling-origin evaluation).
Successive splits grow their training window into the past while the test set
is always the next chronological chunk. Order is never shuffled: for every
split, every training index is strictly earlier than every test index (with
an optional gap between them).
Input convention: samples are assumed to be in chronological row order.
This splitter works purely on positions, not on explicit timestamps — sort
your data by time before using it. (Positional order keeps the API simple and
matches scikit-learn’s TimeSeriesSplit; a timestamp-aware variant is
intentionally out of scope.)
Configuration mirrors scikit-learn:
n_splits— number of train/test splits.max_train_size— cap the training window to a fixed size (a rolling window) instead of an ever-expanding one.gap— drop this many samples between the end of train and the start of test, modelling a real-world delay before an outcome/label is known.test_size— samples per test set (defaults ton_samples / (n_splits + 1)).
use model_selection_rs::splitters::{CvSplitter, TimeSeriesSplit};
let tss = TimeSeriesSplit::new(3).unwrap();
for (train, test) in tss.split(12).unwrap() {
// train is always entirely before test
assert!(train.iter().max() < test.iter().min());
}Implementations§
Source§impl TimeSeriesSplit
impl TimeSeriesSplit
Sourcepub fn new(n_splits: usize) -> Result<Self>
pub fn new(n_splits: usize) -> Result<Self>
Create a TimeSeriesSplit with n_splits expanding-window splits.
§Errors
Returns ModelSelectionError::InvalidSplitCount if n_splits < 1.
Sourcepub fn with_max_train_size(self, max_train_size: usize) -> Self
pub fn with_max_train_size(self, max_train_size: usize) -> Self
Cap the training window to max_train_size samples (rolling window).
Sourcepub fn with_gap(self, gap: usize) -> Self
pub fn with_gap(self, gap: usize) -> Self
Insert a gap of dropped samples between train and test.
Sourcepub fn with_test_size(self, test_size: usize) -> Self
pub fn with_test_size(self, test_size: usize) -> Self
Fix the number of samples in each test set.
Trait Implementations§
Source§impl Clone for TimeSeriesSplit
impl Clone for TimeSeriesSplit
Source§fn clone(&self) -> TimeSeriesSplit
fn clone(&self) -> TimeSeriesSplit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CvSplitter for TimeSeriesSplit
impl CvSplitter for TimeSeriesSplit
Auto Trait Implementations§
impl Freeze for TimeSeriesSplit
impl RefUnwindSafe for TimeSeriesSplit
impl Send for TimeSeriesSplit
impl Sync for TimeSeriesSplit
impl Unpin for TimeSeriesSplit
impl UnsafeUnpin for TimeSeriesSplit
impl UnwindSafe for TimeSeriesSplit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more