👨🎓个人主页:研学社的博客
💥💥💞💞欢迎来到本博客❤️❤️💥💥
🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
📋📋📋本文目录如下:🎁🎁🎁
目录
💥1 概述
本文用三种方法进行预测。 BILSTM、GMDH 及遗传COVID 预测。
📚2 运行结果
2.1 BILSTM预测
2.2 GA NN 预测
2.3 GMDH预测
部分代码:
%% Input
x=load('hopkinsirandeath.txt');
Delays = [10 20 30 40 50];
[Inputs, Targets] = CreateTimeSeriesData(x,Delays);
nData = size(Inputs,2);
Perm = randperm(nData);
% Train
pTrain = 0.8;
nTrainData = round(pTrain*nData);
TrainInd = Perm(1:nTrainData);
TrainInputs = Inputs(:,TrainInd);
TrainTargets = Targets(:,TrainInd);
% Test
pTest = 1 - pTrain;
nTestData = nData - nTrainData;
TestInd = Perm(nTrainData+1:end);
TestInputs = Inputs(:,TestInd);
TestTargets = Targets(:,TestInd);
% Create GMDH Network
params.MaxLayerNeurons = 30; % Maximum Number of Neurons in a Layer
params.MaxLayers = 9; % Maximum Number of Layers
params.alpha = 0; % Selection Pressure
params.pTrain = 0.2; % Train Ratio
% Tran GMDH
gmdh = GMDH(params, TrainInputs, TrainTargets);
% GMDH Model on Train and Test (Validation)
Outputs = ApplyGMDH(gmdh, Inputs);
TrainOutputs = Outputs(:,TrainInd);
TestOutputs = Outputs(:,TestInd);
%% Predict Plots
% figure;
% PlotResults(TrainTargets, TrainOutputs, 'Train Data');
% figure;
% PlotResults(TestTargets, TestOutputs, 'Test Data');
figure;
set(gcf, 'Position', [50, 100, 1200, 450])
[MSE RMSE ErrorMean ErrorStd Errors]=PlotResults(Targets, Outputs, 'All Data');
figure;
plotregression(TrainTargets, TrainOutputs, 'Train Data', ...
TestTargets, TestOutputs, 'TestData', ...
Targets, Outputs, 'GMDH All Data');
% Forecast Plot
fore=180;
sizee=size(x);
sizee=sizee(1,2);
forecasted=Outputs(1,end-fore:end);
forecasted=forecasted+x(end)/2.5;
ylbl=sizee+fore;
t = linspace(sizee,ylbl,length(forecasted));
% Compare the simulated output with measured data to ensure it is a good fit.
nstep=32;
sys = nlarx(Outputs',64);
figure;
set(gcf, 'Position', [50, 200, 1300, 400])
compare(Outputs',sys,nstep);title('Covid Iran Death');
grid on;
%
figure;
regres=compare(Outputs',sys,nstep);title('Covid Iran Death');
b1 = regres\Outputs';
yCalc1 = b1*regres;
scatter(regres,Outputs','MarkerEdgeColor',[0 .5 .5],...
'MarkerFaceColor',[0 .8 .8],...
'LineWidth',1);
hold on
plot(regres,yCalc1,':',...
'LineWidth',2,...
'MarkerSize',5,...
'Color',[0.6350 0.0780 0.1840]);
title(['Regression : ' num2str(b1) ])
grid on
%
figure;
set(gcf, 'Position', [20, 20, 1000, 250])
plot(x,'--',...
'LineWidth',1,...
'MarkerSize',5,...
'Color',[0,0,0.7]);
hold on;
plot(t,forecasted,'-.',...
'LineWidth',2,...
'MarkerSize',10,...
'Color',[0.9,0.5,0]);
title('Johns Hopkins Data for Iran COVID Deaths - Orange is Forcasted')
xlabel('Days - From Jan 2020 Till Dec 2021','FontSize',12,...
'FontWeight','bold','Color','b');
ylabel('Number of People','FontSize',12,...
'FontWeight','bold','Color','b');
datetick('x','mmm');
legend({'Measured','GMDH Forecasted'});
%% Metrics
% Explained Variance (EV)
va=var(Outputs-Targets);vc=var(Targets);
vd=abs(va/vc);vb = vd / 10^floor(log10(vd));
EV=vb*0.1
% MSE
MSE
% RMSE
RMSE
% Mean Error
ErrorMean
% STD Error
ErrorStd
% Mean Absolute Error (MAE)
🎉3 参考文献
部分理论来源于网络,如有侵权请联系删除。
[1]Seyed Muhammad Hossein Mousavi (2023). BILSTM, GMDH and Genetic COVID Forecasting Into Desired Step.
[2]高明,郝妍.基于BiLSTM网络与误差修正的超短期负荷预测[J].综合智慧能源,2023,45(01):31-40.