文档库 最新最全的文档下载
当前位置:文档库 › BP神经网络预测代码

BP神经网络预测代码

BP神经网络预测代码
BP神经网络预测代码

B P神经网络预测代码 Revised as of 23 November 2020

x=[54167 55196 56300 57482 58796 60266 61465 62828 64653 65994 67207 66207 65859 67295 69172 70499 72538 74542 76368 78534

80671 82992 85229 87177 89211 90859 92420 93717 94974 96259 97542 98705 100072 101654 103008 104357 105851 107507 109300 111026

112704 114333 115823 117171 118517 119850 121121 122389 123626 124761 125786 126743 127627 128453 129227 129988 130756 131448 132129 132802

134480

135030

135770

136460

137510]';

% 该脚本用来做NAR预测

% 作者:Macer程

lag=3; % 自回归阶数

iinput=x; % x为原始序列(行向量)

n=length(iinput);

%准备输入和输出数据

inputs=zeros(lag,n-lag);

for i=1:n-lag

%绘制误差的自相关情况(20lags)

figure, parcorr(errors) %绘制偏相关情况

%[h,pValue,stat,cValue]= lbqtest(errors) %Ljung-Box Q检验(20lags)figure,plotresponse(con2seq(targets),con2seq(yn)) %看预测的趋势与原趋势%figure, ploterrhist(errors) %误差直方图

%figure, plotperform(tr) %误差下降线

%% 下面预测往后预测几个时间段

fn=7; %预测步数为fn。

f_in=iinput(n-lag+1:end)';

f_out=zeros(1,fn); %预测输出

% 多步预测时,用下面的循环将网络输出重新输入

for i=1:fn

f_out(i)=net(f_in);

f_in=[f_in(2:end);f_out(i)];end% 画出预测图

figure,plot(1949:2013,iinput,'b',2013:2020,[iinput(end),f_out],'r')

相关文档