| ts_sample | R Documentation |
Split a ts_data into train and test sets.
Extracts test_size rows from the end (minus an optional offset) as the
test set. The remaining initial rows form the training set. The offset
is useful to reproduce experiments with different forecast origins.
ts_sample(ts, test_size = 1, offset = 0)
ts |
A |
test_size |
Integer. Number of rows in the test split (default = 1). |
offset |
Integer. Offset from the end before the test split (default = 0). |
A list with $train and $test (both ts_data).
# Setting up a ts_data and making a temporal split
# Load example dataset and build windows
data(tsd)
ts <- ts_data(tsd$y, 10)
# Separating into train and test
test_size <- 3
samp <- ts_sample(ts, test_size)
# First five rows from training data
ts_head(samp$train, 5)
# Last five rows from training data
ts_head(samp$train[-c(1:(nrow(samp$train)-5)),])
# Testing data
ts_head(samp$test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.