मैं आर में यह कर रहा हूँ यहाँ मेरा डेटा इन-सैंपल और आउट-सैंपल डेटा दोनों के लिए मेरा कोड है:
#accuracy testing for out-of-sample sample#
M<-#data#
deltaT<-#set observations per year,1/4 for quarterly, 1/12 for monthly
horiz<-#set amount of forecasts required
startY<-c(#,#) #set start date
N<-head(M,-horiz)
Nu<-log(Nu)
Nu<-ts(Nu,deltat=deltaT,start=startY)
#Run your forecasting method#
##My forecasting method is arima##
N<-#data#
N<-ts(N,deltat=deltaT,start=startY)
N<-tail(N,horiz)
fitted<-ts(append(fitted(Arimab), fArimab$mean[1]), deltat=deltaT, start = startY) #where Arimab is the ARIMA model and fArimab<-forecast(Arimab, h=horiz*2, simulate= TRUE, fan=TRUE)
N<-log(N)
fitted<-head(fitted,length(N))
error<-N-fitted
percenterror<-100*error/N
plus<-N+fitted
rmse<-function(error)
sqrt(mean(error^2))
mae<-function(error)
mean(abs(error))
mape<-function(percenterror)
mean(abs(percenterror))
smape<-function(error,plus)
mean(200*abs(error)/(plus))
mse<-function(error)
mean(error^2)
me<-function(error)
mean(error)
mpe<-function(percenterror)
mean(percenterror)
accuracy<-matrix(c("rmse","mae","mape","smape","mse","me","mpe",(round(rmse(error),digits=3)),(round(mae(error),digits=3)),(round(mape(percenterror),digits=3)),(round(smape(error,plus),digits=3)),(round(mse(error),digits=3)),(round(me(error),digits=3)),(round(mpe(percenterror),digits=3))),ncol=2,byrow=FALSE)
View(accuracy,title="Accuracy of ARIMA out sample")
#Accuracy testing for the in sample
M<-#data#
deltaT<-#set observations per year,1/4 for quarterly, 1/12 for monthly
horiz<-#set amount of forecasts required
startY<-c(#,#) #set start date
Nu<-log(Nu)
Nu<-ts(Nu,deltat=deltaT,start=startY)
#run your forecasting method#
fitted<-ts(append(fitted(Arimab), fArimab$mean[1]), deltat=deltaT, start = startY)
N<-exp(Nu)
fitted<-exp(fitted)
fitted<-head(fitted,length(N))
error<-N-fitted
percenterror<-100*error/N
plus<-N+fitted
rmse<-function(error)
sqrt(mean(error^2))
mae<-function(error)
mean(abs(error))
mape<-function(percenterror)
mean(abs(percenterror))
smape<-function(error,plus)
mean(200*abs(error)/(plus))
mse<-function(error)
mean(error^2)
me<-function(error)
mean(error)
mpe<-function(percenterror)
mean(percenterror)
accuracy<-matrix(c("rmse","mae","mape","smape","mse","me","mpe",(round(rmse(error),digits=3)),(round(mae(error),digits=3)),(round(mape(percenterror),digits=3)),(round(smape(error,plus),digits=3)),(round(mse(error),digits=3)),(round(me(error),digits=3)),(round(mpe(percenterror),digits=3))),ncol=2,byrow=FALSE)
View(accuracy,title="Accuracy of ARIMA in sample")
उम्मीद है इससे कुछ मदद मिली होगी। अगर आप मेरा पूरा कोड चाहते हैं तो मैं इसे चलाने के लिए इस्तेमाल कर रहा हूं क्योंकि यह बहुत बुनियादी है