hw(train) 中的错误:时间序列的频率应大于 1(预测库)
Error in hw(train): The time series should have frequency greater than 1 (forecast library)
这是什么意思?我的 timeSeries 的频率是 365,不是吗?我想做的是每天做 3 年的预测,一次一天。换句话说,我想得到第二天的预报,365*3次。
library(forecast)
df = read.csv("./files/all_var_df.csv")
ts = as.timeSeries(df[, c(1, 2)])
train = as.timeSeries(ts[0:3285, ])
validation = ts[3285:4380]
fit_hw <- hw(train)
fit2_hw <- hw(validation, model=fit_hw)
onestep_hw <- fitted(fit2_hw)
Error in hw(train): The time series should
have frequency greater than 1.
以下是一些可能有助于您回答问题的信息:
class(train)
> [1] "timeSeries"
head(train, 3)
> 2005-01-01 101634.4
> 2005-01-02 106812.5
> 2005-01-03 119502.8
length(train)
> [1] 3285
在没有实际看到您的数据的情况下,我只能推测。但是,我可以使用 R 中的可用数据集重现此问题。在 R 中的 library(fpp2)
中,数据集 ausair
包含 "Total annual air passengers (in millions) including domestic and international aircraft passengers of air carriers registered in Australia. 1970-2016."
将此数据集作为 ts (air <- window(ausair, start = 1990)
) 读取,我们得到以下内容:
Time Series:
Start = 1990
End = 2016
Frequency = 1
[1] 17.55340 21.86010 23.88660 26.92930 26.88850 28.83140 30.07510 30.95350
[9] 30.18570 31.57970 32.57757 33.47740 39.02158 41.38643 41.59655 44.65732
[17] 46.95177 48.72884 51.48843 50.02697 60.64091 63.36031 66.35527 68.19795
[25] 68.12324 69.77935 72.59770
我现在将使用 hw()
函数来训练:
fc <- hw(air, seasonal = "additive")
这会产生以下错误:
Error in hw(air, seasonal = "additive") :
The time series should have frequency greater than 1.
这里发生的是每个数据点对应一整年。所以 Holt-Winters 方法无法找到季节性。 HW 方法的季节性部分遵循以下等式:
&space;+&space;(1&space;-&space;%5Cgamma)s_%7Bt-m%7D)
其中
项表示季节性,m 表示频率。如果一个时间段内只有 1 个数据点,则谈论重复的季节性模式没有意义。
解决问题的方法是使用 ts()
定义时间序列对象的方式。时间序列函数的一个参数是频率。在没有看到您的数据的情况下,我无法说出该值应该设置为什么。 Here 是一个解释术语频率的网站。这将取决于您的数据表现出的季节性。它是否每周重复一种季节性模式?每个季度?如果没有季节性模式,您可以切换到 holt()
函数,它仅使用指数衰减项和趋势项来查找模式并且不会给出您的错误。
这是什么意思?我的 timeSeries 的频率是 365,不是吗?我想做的是每天做 3 年的预测,一次一天。换句话说,我想得到第二天的预报,365*3次。
library(forecast)
df = read.csv("./files/all_var_df.csv")
ts = as.timeSeries(df[, c(1, 2)])
train = as.timeSeries(ts[0:3285, ])
validation = ts[3285:4380]
fit_hw <- hw(train)
fit2_hw <- hw(validation, model=fit_hw)
onestep_hw <- fitted(fit2_hw)
Error in hw(train): The time series should have frequency greater than 1.
以下是一些可能有助于您回答问题的信息:
class(train)
> [1] "timeSeries"
head(train, 3)
> 2005-01-01 101634.4
> 2005-01-02 106812.5
> 2005-01-03 119502.8
length(train)
> [1] 3285
在没有实际看到您的数据的情况下,我只能推测。但是,我可以使用 R 中的可用数据集重现此问题。在 R 中的 library(fpp2)
中,数据集 ausair
包含 "Total annual air passengers (in millions) including domestic and international aircraft passengers of air carriers registered in Australia. 1970-2016."
将此数据集作为 ts (air <- window(ausair, start = 1990)
) 读取,我们得到以下内容:
Time Series:
Start = 1990
End = 2016
Frequency = 1
[1] 17.55340 21.86010 23.88660 26.92930 26.88850 28.83140 30.07510 30.95350
[9] 30.18570 31.57970 32.57757 33.47740 39.02158 41.38643 41.59655 44.65732
[17] 46.95177 48.72884 51.48843 50.02697 60.64091 63.36031 66.35527 68.19795
[25] 68.12324 69.77935 72.59770
我现在将使用 hw()
函数来训练:
fc <- hw(air, seasonal = "additive")
这会产生以下错误:
Error in hw(air, seasonal = "additive") :
The time series should have frequency greater than 1.
这里发生的是每个数据点对应一整年。所以 Holt-Winters 方法无法找到季节性。 HW 方法的季节性部分遵循以下等式:
其中 项表示季节性,m 表示频率。如果一个时间段内只有 1 个数据点,则谈论重复的季节性模式没有意义。
解决问题的方法是使用 ts()
定义时间序列对象的方式。时间序列函数的一个参数是频率。在没有看到您的数据的情况下,我无法说出该值应该设置为什么。 Here 是一个解释术语频率的网站。这将取决于您的数据表现出的季节性。它是否每周重复一种季节性模式?每个季度?如果没有季节性模式,您可以切换到 holt()
函数,它仅使用指数衰减项和趋势项来查找模式并且不会给出您的错误。