I have the following error when using the step_fourier
function.
This error only occurs when I use time_series_split
split with my data to convert paneled time series into training and testing sets. When I input the dataset directly, the error does not occur.
Here the error occurs:
library(recipes)
library(tidyverse)
library(tidyquant)
library(timetk)
dados <- FANG %>% select(symbol,date,volume)
splits <- dados %>%
time_series_split(
assess = "1 months",
cumulative = TRUE
)
# Create a recipe object with a timeseries signature step
rec_obj <- recipe(volume ~ ., data = training(splits)) %>%
step_fourier(date,period=365, K = 1)
rec_obj %>% prep() %>% juice() %>% glimpse()
Follow the error:
Rows: 3,948
Columns: 5
$ symbol <fct> FB, AMZN, NFLX, GOOG, FB, AMZN, NFLX, GOOG, FB, AMZN,…
$ date <date> 2013-01-02, 2013-01-02, 2013-01-02, 2013-01-02, 2013…
$ volume <dbl> 69846400, 3271000, 19431300, 5101500, 63140600, 27509…
$ date_sin365_K1 <dbl> NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN…
$ date_cos365_K1 <dbl> NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN…
Warning messages:
1: Problem while computing `date_sin365_K1 = timetk::fourier_vec(...)`.
ℹ NaNs produced
2: Problem while computing `date_cos365_K1 = timetk::fourier_vec(...)`.
ℹ NaNs produced
Here the error does not occur:
library(recipes)
library(tidyverse)
library(tidyquant)
library(timetk)
dados <- FANG %>% select(symbol,date,volume)
#splits <- dados %>%
# time_series_split(
# assess = "1 months",
# cumulative = TRUE
# )
# Create a recipe object with a timeseries signature step
rec_obj <- recipe(volume ~ ., data = dados) %>%
step_fourier(date,period=365, K = 1)
rec_obj %>% prep() %>% juice() %>% glimpse()
Rows: 4,032
Columns: 5
$ symbol <fct> FB, FB, FB, FB, FB, FB, FB, FB, FB, FB, FB, FB, FB, F…
$ date <date> 2013-01-02, 2013-01-03, 2013-01-04, 2013-01-07, 2013…
$ volume <dbl> 69846400, 63140600, 72715400, 83781800, 45871300, 104…
$ date_sin365_K1 <dbl> 0.2051045, 0.2219215, 0.2386728, 0.2884824, 0.3049212…
$ date_cos365_K1 <dbl> 0.9787401, 0.9750645, 0.9711001, 0.9574852, 0.9523776…
>
Can anyone please help me?
I solve this
rec_obj <- recipe(volume ~ ., data = training(splits)) %>%
step_arrange(symbol,date) %>%
step_fourier(date,period=365, K = 1) %>%
step_arrange(date,symbol) ```