matlab 神经网络预测时间序列示例(水痘模型)

这篇博客展示了如何运用神经网络对时间序列数据进行预测,以水痘病例数为例。首先导入和绘制数据,然后创建并训练一个开环神经网络。接着计算性能指标,包括训练、验证和测试集上的误差。最后,进行了多步和一步超前预测,评估了网络的预测能力。
摘要由CSDN通过智能技术生成

神经网络预测时间序列示例(水痘模型)

clc,clear;
close all;
%% Importing Data and plotting
data=chickenpox_dataset;
data=[data{:}];
figure
plot(data)
xlabel("Month")
ylabel("Cases")
title("Monthy Cases of Chickenpox")
%% Converting matrix to cell
[t1,t2]=size(data);
Target=mat2cell(data,t1,ones(1,t2));
T=Target;
%% Creating open loop network
trainFcn='trainbr';
feedbackdelays=1:2;
hiddenLayerSize=10;
net=narnet(feedbackdelays,hiddenLayerSize,'open',trainFcn);
[x,xi,ai,t]=preparets(net,{},{},T);
net.divideFcn='divideind';
net.divideMode='time';
net.divideParam.trainInd=1:400;
net.divideParam.valInd=401:450;
net.divideParam.testInd=451:498;
net.performFcn='mse';
[net,tr]=train(net,x,t,xi,ai);
y=net(x,xi,ai);
%% Calculating performance
trainTargets=gmultiply(t,tr.trainMask);
valTargets=gmultiply(t,tr.valMask);
testTargets=gmultiply(t,tr.testMask);
trainPerformance=perform(net,trainTargets,y)
valPerformance=perform(net,valTargets,y)
testPerformance=perform(net,testTargets,y)
%% Closing the network
view(net)
netc=closeloop(net);
netc.name=[net.name '- Closed Loop'];
view(netc)
[xc,xic,aic,tc]=preparets(netc,{},{},T);
yc=netc(xc,xic,aic);
closedLoopPerformance=perform(net,tc,yc)
%% Multi step prediction
[x1,xio,aio,t]=preparets(net,{},{},T);
[y1,xfo,afo]=net(x1,xio,aio);
[netc,xic,aic]=closeloop(net,xfo,afo);
[y2,xfc,afc]=netc(cell(0,20),xic,aic);
y1_1=cell2mat(y1);
y2_1=cell2mat(y2);
plot(1:496,y1_1,'-b');
hold on
plot(496:515,y2_1,'-k');
%% Step-Ahead prediction
nets=removedelay(net);
nets.name=[net.name '- Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts]=preparets(nets,{},{},T);
ys=nets(xs,xis,ais);
stepAheadPerformance=perform(nets,ts,ys)
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值