Description Usage Arguments Details Value Methods (by class) References
Generate test/train set for time series. Each training set consists of observations before the test set. This is also called "evaluation on a rolling forecasting origin".
1 2 3 4 5 6 7 8 9 10 11 | crossv_ts(data, ...)
## S3 method for class 'data.frame'
crossv_ts(data, horizon = 1L, test_size = 1L,
test_partial = FALSE, train_partial = TRUE, train_size = n,
test_start = NULL, from = 1L, to = n, by = 1L, ...)
## S3 method for class 'grouped_df'
crossv_ts(data, horizon = 1L, test_size = 1L,
test_partial = FALSE, train_partial = TRUE, train_size = n,
test_start = NULL, from = 1L, to = n, by = 1L, ...)
|
data |
A data frame |
... |
Arguments passed to methods |
horizon |
Difference between the first test set observation and the last training set observation |
test_size |
Size of the test set |
test_partial |
If |
train_partial |
Same as |
train_size |
The maximum size of the training set. This allows for a rolling window training set, instead of using all obsservations from the start of the time series. |
test_start, from, to, by |
An integer vector of the starting index values of the test set.
|
In time-series cross-validation the training set only uses observations that are prior to the test set. Suppose the time series has n observations, the training set has a maximum size of r <= n and minimum size of s >= r. and the test set has a maximum size of p <= n and minimum size of q >= p. For indices i \in \{1, …, N\}:
Select observations i, …, \max{p, n} for the test set.
Select observations \max{i - h - p}, …, i - h for the training set.
If the test set has a size of at least q
and the training set
has a size of at least r
.
A data frame with k
the following columns:
A list of resample
objects. Training sets.
An integer vector of identifiers.
data.frame
: Data frame method. This rows are assumed to be ordered.
grouped_df
: Grouped data frame method. The groups are assumed to be ordered, and
the cross validation works on groups rather than rows.
Hyndman RJ (2017). forecast: Forecasting functions for time series and linear models. R package version 8.0, URL.
Hyndman RJ and Khandakar Y (2008). "Automatic time series forecasting: the forecast package for R." Journal of Statistical Software. URL.
Rob J. Hyndman. http://robjhyndman.com/hyndsight/tscv/. December 5, 2016.
Rob J. Hyndman. http://robjhyndman.com/hyndsight/tscvexample/. August 26, 2011.
Rob J. Hyndman and George Athanasopoulos. "Evaluating Forecast Accuracy." URL.
Max Kuhn. "Data splitting for Time Series." The caret Package. 2016-11-29. URL.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.