time_splits: Generate Train/Test Splits

View source: R/sequence.R

time_splitsR Documentation

Generate Train/Test Splits

Description

Generates train/test splits given a vector of dates and other options

Usage

time_splits(
  x,
  start = x[1],
  test_length = 1,
  by = test_length,
  window_size = NULL,
  calendar_end = NULL,
  complete_index = TRUE,
  ...
)

Arguments

x

a vector of timestamps (POSIXct) or dates (Date) in the dataset

start

starting date (first estimation/train date)

test_length

type of calendar period to split on

by

every how many periods to split on

window_size

the size of the training set (for moving window). If NULL will use an expanding window.

calendar_end

an optional function to use for the period ending split, such as calendar_eow, applied to x. This should be greater in frequency than the underlying frequency of x (i.e. do not use calendar_eow on monthly indices). This overwrites the use of window_size.

complete_index

whether to return the full indices for train and test else just the start and end indices.

...

any additional parameters passed to the calendar_end function. For example, the “day” argument when using the calendar_eow function.

Value

A list with each slot having the training dates and test dates

Note

For months, quarters and years this will split into the end date of these. For splitting into mins or hours, x must also have this resolution else will throw an error. Additionally, the strict requirement of regularly spaced time is required (no gaps).

Author(s)

Alexios Galanos


tsaux documentation built on April 4, 2025, 3:08 a.m.