Able to calculate accuracy of forecasting?

Dhuwaragish Ravichandrakumar on 7 Apr 2022 (Edited on 7 Apr 2022)
Latest activity Reply by Dhuwaragish Ravichandrakumar on 8 Apr 2022

Hi all, I currently have a forecasting of a variable based on the data that I collected. But is there a way to calculate what is the accuracy for the forecast? Thanks.

Christopher Stapels
Christopher Stapels on 7 Apr 2022

Can you share the code you are using to make the forecast?

Dhuwaragish Ravichandrakumar
Dhuwaragish Ravichandrakumar on 7 Apr 2022

Sure, heres the code

startDate = datetime('April 03, 2022 12:00:00 PM');
endDate = datetime('April 04, 2022 12:00:00 PM');
dateRange = startDate:endDate;
data = thingSpeakRead(1695845,'DateRange',dateRange,'Fields',1);
sampleTime = 5;
IDdata = iddata(data,[],sampleTime,'OutputName',{'CO2'},'TimeUnit','minutes')
trend = getTrend(IDdata,0);
IDdata = detrend(IDdata,0);
modelOrder = 8;
sys = ar(IDdata,modelOrder);
numSamples = 400;
[yf,x0,sysf,yf_sd,x,x_sd] = forecast(sys,IDdata,numSamples);
IDdata = retrend(IDdata,trend);
yf = retrend(yf,trend);
figure;
UpperBound = iddata(yf.OutputData+1*yf_sd,[],yf.Ts,'Tstart',yf.Tstart,'TimeUnit','minutes');
LowerBound = iddata(yf.OutputData-1*yf_sd,[],yf.Ts,'Tstart',yf.Tstart,'TimeUnit','minutes');
plot(IDdata(:,:,[]),'r',yf(:,:,[]),'b');
hold on
plot(UpperBound,'k--',LowerBound,'k--');
legend({'measured','forecasted','1 sd uncertainty'},'Location','best');
xlabel('Time');
ylabel('CO2');
Christopher Stapels
Christopher Stapels on 7 Apr 2022

I assume you are looking for a confidence in the forecast, and not the quality of the forecast once the result is known. I think the width of the bounds is a good representation of the confidence. The difference in upper bound to lower bound scaled by the mean of the two would give a good relative measure of confidence. You might want to square the values first to avoid the possible effects of negative values (then take the square root of the result).

Dhuwaragish Ravichandrakumar
Dhuwaragish Ravichandrakumar on 8 Apr 2022

Thanks Christopher. Confidence in forecast is something I can add on too but I'm looking for the quality of forecast. Do you know about it?

Tags

No tags entered yet.