Create a torch dataset for time series data from a data.frame-like object

as_ts_dataset(
  data,
  formula,
  index = NULL,
  key = NULL,
  predictors = NULL,
  outcomes = NULL,
  categorical = NULL,
  timesteps,
  horizon = 1,
  sample_frac = 1,
  scale = TRUE,
  jump = 1,
  ...
)

Arguments

data

(data.frame) An input data.frame object with. For now only single data frames are handled with no categorical features.

formula

(formula) A formula describing, how to use the data

index

(character) The index column name.

key

(character) The key column name(s). Use only if formula was not specified.

predictors

(character) Input variable names. Use only if formula was not specified.

outcomes

(character) Target variable names. Use only if formula was not specified.

categorical

(character) Categorical features.

timesteps

(integer) The time series chunk length.

horizon

(integer) Forecast horizon.

sample_frac

(numeric) Sample a fraction of rows (default: 1, i.e.: all the rows).

scale

(logical or list) Scale feature columns. Logical value or two-element list. with values (mean, std)

Note

If scale is TRUE, only the input variables are scale and not the outcome ones.

See: Is it necessary to scale the target value in addition to scaling features for regression analysis? (Cross Validated)

Examples

library(rsample)
library(dplyr, warn.conflicts = FALSE)

suwalki_temp <-
   weather_pl %>%
   filter(station == "SWK")

# Splitting on training and test
data_split <- initial_time_split(suwalki_temp)

train_ds <-
 training(data_split) %>%
 as_ts_dataset(tmax_daily ~ date + tmax_daily + rr_type,
               timesteps = 20, horizon = 1)
#> Categorical variables found (1): rr_type

train_ds[1]
#> Error in torch_int(): could not find function "torch_int"