Forecasting / Input response series data must be non-empty and a column vector.

10 Ansichten (letzte 30 Tage)
Meryem Ml
Meryem Ml am 8 Feb. 2021
Bearbeitet: Pavl M. am 21 Nov. 2024 um 14:10
Hello i am trying to creat a simple forecasting algo for long terms (foraward 10 yrs based on the data from yrs back ) so my code is below, when i run it, i got this error
Input response series data must be non-empty and a column vector.
Error in Untitled2 (line 18)
EstMdl = estimate(Mdl,data);
Please some help guys.
.
.
.
load data
yrs = evolutiondelademand.VarName1;
demand = evolutiondelademand.VarName2;
A= [yrs,demand];
data = iddata(A,[]);
plot (yrs,demand)
%%figure
plot(yrs,demand)
xlabel('years')
ylabel('demand')
past_data = data.OutputData(1:50);
Mdl = arima(2,0,0);
opt = forecastOptions('InitialCondition','e');
K = 100;
EstMdl = estimate(Mdl,data);
[yF,yMSE] = forecast(EstMdl,60,'Y0',data);
legend('Measured','Forecasted')

Antworten (1)

Pavl M.
Pavl M. am 21 Nov. 2024 um 12:49
Bearbeitet: Pavl M. am 21 Nov. 2024 um 14:10
%load data
%yrs = evolutiondelademand.VarName1;
%demand = evolutiondelademand.VarName2;
odata = xlsread('TitanX Historical Numbers.xlsx');
Dlength = 88;
ts = 1
ts = 1
time = (0:ts:Dlength-1)' %odata(1:Dlength,1) % Time column (1st column)
time = 88×1
0 1 2 3 4 5 6 7 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
demand = odata(1:Dlength,2)
demand = 88×1
45499 45500 45501 45502 45503 45504 45505 45506 45507 45508
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%areTimestampsRegular = isregular(demand)
areTimestampsSorted = issorted(demand)
areTimestampsSorted = logical
1
%w = convert2weekly(odata,Aggregation="mean")
%areTimestampsWRegular = isregular(w,"years")
yrs = double(time)
yrs = 88×1
0 1 2 3 4 5 6 7 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A= [yrs,demand];
data = iddata(A,[])
data = Time domain data set with 88 samples. Sample time: 1 seconds Outputs Unit (if specified) y1 y2
figure
plot(yrs,demand)
xlabel('years')
ylabel('demand')
title('InputData')
Npastsamples = 50;
past_data = data.OutputData(1:Npastsamples);
%nMdl0 = nlarx(data, [2 2 1;2 2 1])
Mdl0 = arima(3,2,1)
Mdl0 =
arima with properties: Description: "ARIMA(3,2,1) Model (Gaussian Distribution)" SeriesName: "Y" Distribution: Name = "Gaussian" P: 5 D: 2 Q: 1 Constant: NaN AR: {NaN NaN NaN} at lags [1 2 3] SAR: {} MA: {NaN} at lag [1] SMA: {} Seasonality: 0 Beta: [1×0] Variance: NaN
Mdl = gjr(9,21)
Mdl =
gjr with properties: Description: "GJR(9,21) Conditional Variance Model (Gaussian Distribution)" SeriesName: "Y" Distribution: Name = "Gaussian" P: 9 Q: 21 Constant: NaN GARCH: {NaN NaN NaN NaN NaN NaN NaN NaN NaN} at lags [1 2 3 4 5 6 7 8 9] ARCH: {NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN} at lags [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21] Leverage: {NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN} at lags [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21] Offset: 0
Mdl2 = garch(Constant=0.05,GARCH=0.91,ARCH=0.04) %Stationary Model
Mdl2 =
garch with properties: Description: "GARCH(1,1) Conditional Variance Model (Gaussian Distribution)" SeriesName: "Y" Distribution: Name = "Gaussian" P: 1 Q: 1 Constant: 0.05 GARCH: {0.91} at lag [1] ARCH: {0.04} at lag [1] Offset: 0
opt = forecastOptions('InitialCondition','e');
K = 100;
Nhor = 60; %actual forecasting horizon
rng("default") % For reproducibility
[vS,yS] = simulate(Mdl2,50)
vS = 50×1
0.9716 1.0648 1.2363 1.2118 1.1577 1.1827 1.1351 1.0883 1.5978 1.9941
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
yS = 50×1
1.8076 -2.3309 0.9586 0.3509 -1.4070 -0.4715 0.3650 3.7330 3.5006 -1.9062
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(vS)
figure
plot(yS)
y0 = yS(1);
v0 = vS(1);
y = yS(2:end);
v = vS(2:end);
res = infer(Mdl2,y) % Retrieve inferred residuals
res = 49×1
2.4242 2.4734 2.3375 2.1821 2.1149 1.9834 1.8602 2.3002 2.6334 2.5917
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(res)
foreValues2 = forecast(Mdl2,Npastsamples,'Y0',demand) % forecast
foreValues2 = 50×1
1.0e+08 * 9.2344 8.7727 8.3341 7.9174 7.5215 7.1454 6.7882 6.4488 6.1263 5.8200
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(foreValues2)
data(:,1)'
ans = Time domain data set with 88 samples. Sample time: 1 seconds Outputs Unit (if specified) y1
EstMdl = estimate(Mdl0,demand);
Warning: Lower bound constraints are active; standard errors may be inaccurate.
ARIMA(3,2,1) Model (Gaussian Distribution): Value StandardError TStatistic PValue _____ _____________ __________ _______ Constant 0 0 NaN NaN AR{1} 0 0 NaN NaN AR{2} 0 0 NaN NaN AR{3} 2e-12 0 Inf 0 MA{1} 2e-12 0 Inf 0 Variance 2e-07 2.6752e-07 0.74759 0.45471
[yF,MSEError] = forecast(EstMdl,Nhor,'Y0',demand)
yF = 60×1
45587 45588 45589 45590 45591 45592 45593 45594 45595 45596
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
MSEError = 60×1
1.0e+00 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
tn = [yrs; (yrs(end):1:yrs(end)+Nhor-1)']
tn = 148×1
0 1 2 3 4 5 6 7 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
plot(tn,[demand; zeros(1,Nhor)'],'b',tn,[zeros(1,Dlength)'; yF],'g')
xlabel('years')
ylabel('demand')
title('Historical in blue and Forecast in green')
figure
plot(tn,[demand; yF])
xlabel('years')
ylabel('demand')
title('Merged Historical and Forecast Data')
%Green curve after input max year Dlength=88 is predicted(forseen,anticipated),
% so the predictions/forecast are correct
% correct )))

Kategorien

Mehr zu Conditional Mean Models finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by