ARIMA模型(Autoregressive Integrated Moving Average Model) ARIMA模型,将非平稳时间序列转化为平稳时间序列,然后将因变量仅对它的滞后值以及随机误差项的现值和滞后值进行回归所建立的模型。
install.packages(“forecast”) 拟合曲线的方法 auto.arima(ts) forecast(arimaModel,h)
代码实现:
#install.packages('forecast')
library(forecast)
data <- read.csv("data.csv", fileEncoding="UTF8")
data$均值 <- data$总销量/data$分店数
plot(data$均值, type='l')
freq <- spec.pgram(data$均值, taper=0, log='no', plot=FALSE);
start <- which(freq$spec==max(freq$spec))
frequency <- 1/freq$freq[which(freq$spec==max(freq$spec))]
meanTS <- ts(
data$均值[start:length(data$均值)],
frequency=frequency
)
meanARIMA = auto.arima(meanTS)
meanARIMAForecast = forecast(meanARIMA, h=7);
meanARIMAForecast$mean
Time Series:
Start = 8.8
End = 9.7
Frequency = 6.66666666666667
[1] 41.87608 44.42713 41.13537 46.31410 44.36805 43.63064 43.48562
plot(meanARIMAForecast)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有