如何使用season函数在寓言-R包中实现每小时和每周的季节性?

问题描述

我必须为2000个不同的时间序列创建每小时的预测。我的系列每小时和每周都有很强的季节性。为了处理每小时的季节性,我使用了season("day")选项。但是,我假设season("week")每周将创建168个虚拟变量,这在计算问题上将是一个问题。

您知道使用tsibble或fabletools程序包创建日间假人的快速方法

ts_forecast1 <- train%>% filter(store_number==288) %>% collect()%>% 
mutate(store_number = factor(store_number)) %>% group_by(store_number) %>%  
filter(sales!=0) %>% tsibble::fill_gaps(sales=100) %>%
fabletools::model(Arima = ARIMA(log(sales) ~  season("day") +fourier("week",K = 8)))

解决方法

您的代码已经包含答案。

season("day")将创建23个虚拟变量,因为一天中有24小时。 season("week")将在一周的168小时内创建167个虚拟变量。要使用更少的系数,请将season()替换为fourier(),然后使用K来控制系数的数量(等于两倍的K)。