How to identify the best frequency in a time series?

99封情书 提交于 2019-12-04 17:04:56

Usually, the frequency (or seasonality, you seem to be using the words interchangeably in your post) is determined by domain knowledge. For example if I am working in the restaurant business, and I am analyzing an hourly data set of customers, I know that I will have a 24 hour frequency, with spikes during lunch time and dinner time, and another 168 hour frequency (24 * 7) because there will be a weekly pattern to my customers.

If for some reason, you don't have domain knowledge, you can use the ACF and the PACF, as well as Fourrier analysis to finds the best frequencies for your data.

Have any way to put the frequency by day of the week and by month?

With Holt-Winters, no. HW takes only one seasonal component. For multiple seasonal components, you should try TBATS. As Xiaoxi Wu pointe out, FB Prophet can model multiple seasonalities, and Google's BSTS package can as well.

Another thing, does it make any difference I take the whole last year or just a part of it to use in the Holt-Winters method?

Yes it does. I you want to model a seasonality, then you need at least two times the seasonal period to be able to model it (preferably more), otherwise your model has no way of knowing whether a spike is a seasonal variation or just a one time impulse. So for example to model a weekly seasonality, you need at least 14 days of training data (plus whatever you will use for testing, and for a yearly seasonality, you will need at least 730 days of data, etc....

Looks like you have daily data and you would like to forecast for the next three months. The question here is do you need daily forecasting or weekly forecasting or just monthly forecasting? I guess you will probably need daily or weekly forecast. If you need weekly forecast, it might be easier to group the data first by week and then run forecast.

A very good tool to use for daily data is the Facebook's new Prophet package. It will work with dataframe instead of ts project, which makes it so much easier to handle with. And you can quickly get daily (if you have hourly data or so), weekly and monthly seasonality from some build-in function, like plot_components. Here is a quick start tutorial by Facebook. They have API for both Python and R.

Here are some quick code to plot the weekly and monthly seasonality (is there is any) with Prophet.

library(prophet)
library(dplyr)
df <- FID_DataSet %>% rename(ds = date, y = Value)
m <- prophet(df)
future <- make_future_dataframe(m, periods = 365)
forecast <- predict(m, future)
plot(m, forecast) # plot out the forecast
prophet_plot_components(m, forecast) # plot out the components: trend, weekly and yearly seasonality if there is any.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!