as_ts_dataset: Create a torch dataset for time series data from a...

View source: R/as-ts-dataset.R

as_ts_datasetR Documentation

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

Description

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

Usage

as_ts_dataset(
  data,
  formula,
  timesteps,
  horizon = 1,
  sample_frac = 1,
  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

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).

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.

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")

debugonce(as_ts_dataset.data.frame)

# 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)

train_ds[1]

train_ds <-
 training(data_split) %>%
 as_ts_dataset(tmax_daily ~ date + tmax_daily + rr_type + lead(rr_type),
               timesteps = 20, horizon = 1)

train_ds[1]

train_ds <-
 training(data_split) %>%
 as_ts_dataset(tmax_daily ~ date + tmax_daily + rr_type + lead(tmin_daily),
               timesteps = 20, horizon = 1)

train_ds[1]


krzjoa/torchts documentation built on June 24, 2022, 5:30 a.m.