split_data {tsLSTMx} | R Documentation |
Split data into training and validation sets
Description
This function takes a data frame and splits it into training and validation sets.
Usage
split_data(new_data, val_ratio = 0.1)
Arguments
new_data |
The data frame to be split. |
val_ratio |
The ratio of the data to be used for validation (default is 0.1). |
Value
A list containing the training and validation data frames.
Examples
data <- data.frame(
Date = as.Date(c("01-04-18", "02-04-18", "03-04-18", "04-04-18", "05-04-18",
"06-04-18", "07-04-18", "08-04-18", "09-04-18", "10-04-18",
"11-04-18", "12-04-18", "13-04-18", "14-04-18", "15-04-18",
"16-04-18", "17-04-18", "18-04-18", "19-04-18", "20-04-18"),
format = "%d-%m-%y"),
A = c(0, 0, 4, 12, 20, 16, 16, 0, 12, 18, 12, 18, 18, 0, 0, 33, 31, 38, 76, 198)
)
check_and_format_data(data)
# Add a new column 'X' based on the values in the second column
data$X <- ifelse(data$A != 0, 1, 0)
result_embed <- embed_columns(data = data, n_lag = 2)
new_data <- result_embed$data_frame
embedded_colnames <- result_embed$column_names
result_split <- split_data(new_data = new_data, val_ratio = 0.1)
train_data <- result_split$train_data
validation_data <- result_split$validation_data
[Package tsLSTMx version 0.1.0 Index]