Hi I am trying to forecast for multiple server for CPU Utilization , But
currently i am getting it for for one week , when ever i am trying to get more
than one week it gives me error. Secondly in the one week forecast values i am
getting the weekend date as the last week end in the original data set , where
as it should be one week after that . Below is my code
Let me know if anything else is required
Code
input_data <- read.csv("input.csv", header= TRUE)
head(input_data)
str(input_data)
library("forecast")
library("DBI")
library("RPostgreSQL")
library("lubridate")
Products = unique(input_data["Server.Name"][,])
output = matrix(0,nrow=(length(Products)*(5)),ncol=7)
colnames(output)
c(
"Product",
"DATE",
"Forecast",
"Lo_80",
"Hi_80 ",
"Lo_95",
"Hi_95"
)
for (i in Products) {
train =
head(input_data["PERCENT_USED"][input_data["Server.Name"]==i]
, 90)
train = ts(train[1:(length(train))])
fc1 = auto.arima(train)
pred1 = forecast( fc1)
fit1_acry = accuracy(pred1)
fc2 = ets(train)
pred2 = forecast( fc2 )
fit2_acry = accuracy(pred2 )
MAPE = data.frame ( fit1_MAPE = fit1_acry[,'MAPE'],
fit2_MAPE = fit2_acry[,'MAPE']
)
best = which.min(MAPE)
BestModel = get(paste('fc',best,sep=""))
forecastoutput = rbind(data.frame(forecast(BestModel, h=1)) )
forecast_date =
rbind(tail(input_data["DATE"][input_data["Server.Name"]==i],(1)))
row_index = which(Products==i)
output[row_index,1] = i
output[row_index,2] = forecast_date
output[row_index,3] = (round(forecastoutput$Point.Forecast,2))
output[row_index,4] = as.numeric(round(forecastoutput$Lo.80,2))
output[row_index,5] = as.numeric(round(forecastoutput$Hi.80,2))
output[row_index,6] = as.numeric(round(forecastoutput$Lo.95,2))
output[row_index,7] = as.numeric(round(forecastoutput$Hi.95,2))
output_onestep = data.frame(output)
}
output_onestep
[[alternative HTML version deleted]]