在R中使用SARIMAX的半小时间隔预测

时间:2019-02-28 22:23:35

标签: r time-series forecasting arima

我正在尝试使用R为每半小时间隔到达支持中心的呼叫到达量预测。以下是我正在使用的代码。

library(TSA)
library(forecast)

 # Determine seasonality of time series
ts_report = read.csv("C:/Users/call_volume.csv")
p = periodogram(ts_report$contacts)


# Sort by the power of the signal
df = data.frame(freq=p$freq, spec=p$spec)
sorted_by_power = df[order(-df$spec),]

# Convert the frequency to time 
calculate_periodicity = 1 / sorted_by_power$freq
print(calculate_periodicity)

# Conver to msts package to plug into fourier
msts_usage = msts(ts_report$contacts,seasonal.periods = c(335, 48, 168, 68, 112, 62, 18225))
log_msts_usage = log(msts_usage + 0.00000000000001)

# calculate the order of the arima model
usage_arima_model <- auto.arima(log_msts_usage, 
xreg=fourier(log_msts_usage,K=c(2, 2, 2, 2, 2, 2, 2)), seasonal=FALSE)

# forecast using the arima model
usage_forecast = forecast(usage_arima_model, xreg=fourier(log_msts_usage, K=c(2, 2, 2, 2, 2, 2, 2), h=1488))

# set values in recursive list "usage_forecast" to exponential values

usage_forecast$mean= exp(usage_forecast$mean)
usage_forecast$x = exp(usage_forecast$x)
usage_forecast[["lower"]] = exp(usage_forecast[["lower"]])
usage_forecast[["upper"]] = exp(usage_forecast[["upper"]])

# plot
autoplot(usage_forecast, xlab = 'Time', ylab = 'Usage')

当我在未将msts_usage设置为log(msts_usage)的情况下运行此命令时,我得到了一个负的预测值,这对于呼叫中心没有意义。因此,我一直在尝试对msts_usage的日志值使用Arima模型。但是,一旦创建了预测,我就需要将数据转换回原始比例。这是我遇到问题的地方。

由于它是一个递归列表,因此我无法在usage_forecast上运行exp(),因此我试图在列表中找到合适的值来运行exp()。当我在均值上运行exp()时,x将自动绘图的Y访问量降低和提高,将其缩放至8e + 16,这使该图不可读。

我希望有人能够帮助我弄清楚我是否做对了,以及应该使用exp()重新缩放哪些值

0 个答案:

没有答案