尝试使用 R 编程中的 UCI 存储库数据集预测未来 24 小时的温度

Trying to forecast the next 24hrs temperature using UCI repository datasets in R programming

您好,我访问了 UCI 存储库中的数据集 http://archive.ics.uci.edu/ml/datasets/Air+Quality

我正在尝试预测接下来的 24 小时 temperature.Below 是我编写的代码

用NA填充缺失值

library(plyr)
AirQualityUCI[AirQualityUCI==-200.0]<-NA

用每列的平均值替换 NA

for(i in 1:ncol(AirQualityUCI)){
 AirQualityUCI[is.na(AirQualityUCI[,i]),i] <- mean(AirQualityUCI[,i], na.rm = TRUE)
}

绘制时间序列

plot(AirQualityUCI$T, type = "l")

如何以小时为单位设置频率并预测接下来 24 小时的温度?

Tempts <- ts(AirQualityUCI)
Temprforecasts <- HoltWinters(Tempts, beta=FALSE, gamma=FALSE)
library(forecast)
accuracy(Temprforecasts,24)

出现以下错误

Error in attr(x, "tsp") <- value : 
  invalid time series parameters specified
library(readxl)
AirQualityUCI <- read_excel("AirQualityUCI.xlsx") 

library(plyr)
AirQualityUCI[AirQualityUCI==-200.0]<-NA

#First, limit to the one column you are interested in (make sure data is sorted by time variable before doing this)
library(data.table)
temp <- setDT(AirQualityUCI)[,c("T")]

#Replace NA with mean
temp$T <- ifelse(is.na(temp$T), mean(temp$T, na.rm=TRUE), temp$T)

#Create time series object...in this case freq = 365 * 24 (hours in year)
Tempts <- ts(temp, frequency = 365*24)

#Model
Temprforecasts <- HoltWinters(Tempts, beta = FALSE, gamma = FALSE)

#Generate next 24 hours forecast
library(forecast)
output.forecast <- forecast.HoltWinters(Temprforecasts, h = 24)