我的预测相对误差怎么如此大,请大家给点建议
clear allclc
% 1989-2003 所有原始数据
m_data=[16909.2 112704 601.5 1373.9 5762.01;
18547.9 114333 686.3 1510.2 6126.03;
21617.8 115823 708.6 1700.6 6696.82;
26638.1 117171 784.0 2026.6 7455.41;
34634.4 118517 921.6 2577.4 8201.17;
46759.4 119850 1221.0 3496.2 9046.51;
58478.1 121121 1577.7 4283.0 9886.36;
67884.6 122389 1926.1 4838.9 10570.29;
74462.6 123626 2090.1 5160.3 11039.11;
78345.2 124761 2162.0 5425.1 11347.30;
82067.5 125786 2210.3 5854.0 12092.28;
89468.1 126743 2253.4 6280.0 13466.22;
97314.8 127627 2366.4 6859.6 14682.51;
105172.3 128453 2475.6 7702.8 16400.14;
117251.9 129227 2622.2 8472.2 18910.12]'
% 将训练集、预测集一起进行归一化
p=m_data(1:4,:) % 输入
t=m_data(5,:) % 输出
for i=1:4
pn(i,:)=(p(i,:)-min(p(i,:)))/(max(p(i,:))-min(p(i,:)));
end
tn=(t-min(t))/(max(t)-min(t))
pn
%---------------------------隐层神经元确定------------------------
EPOCHS=10000;
GOAL=0.000005;
a=3:15; % 隐层神经元数目
res=zeros(size(a));% 用于存储误差,先初始化为0
% 用于训练集
P=pn(:,1:12)
T=tn(1:12)
for i=1:length(a)
net=newff(minmax(P),,{'tansig','purelin'},'trainscg');
net.trainParam.epochs=EPOCHS;
net.trainParam.show=50;
net.trainParam.goal=GOAL;
% net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5;
% net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75;
% net.b{1,1}=zeros(size(net.b{1,1}))+0.5;
% net.b{2,1}=zeros(size(net.b{2,1}));
net=init(net);
net=train(net,P,T);
Y=sim(net,P);
E=T-Y;
ERROR=mse(E,net);
res(i)=norm(ERROR);
end
% 选取最优神经元数,no 为使得误差最小的隐层神经元个数
number=find(res==min(res)); % 记录res中最小值的索引值
% if(length(number)>1)no=number(1)
% else no=number
% end
no=a(number)
clear ERROR res
% 选定隐层神经元数目后,建立网络,训练仿真
net=newff(minmax(P),,{'tansig','purelin'},'trainscg');
net.trainParam.epochs=EPOCHS;
net.trainParam.show=50;
net.trainParam.goal=GOAL;
% net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5;
% net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75;
% net.b{1,1}=zeros(size(net.b{1,1}))+0.5;
% net.b{2,1}=zeros(size(net.b{2,1}));
net=init(net);
net=train(net,P,T);
Y=sim(net,P)
E=T-Y;
ERROR=mse(E,net);
R=norm(ERROR);
save net; % 保存网络
% 2001-2003年作为预测对象
input=pn(:,13:15)
out=sim(net,input)
% 输出反归一化
Y1=Y*(max(t(1:12))-min(t(1:12)))+min(t(1:12))
prediction=out*(max(t(1:12))-min(t(1:12)))+min(1:12)
% 计算相对误差
yucewucha= abs(prediction-t(13:15))./t(13:15)
t(13:15)
% 误差图
figure(1)
plot(1:3,t(13:15),'b*-',1:3,prediction,'ro:')
请大家帮我看看,为什么我的预测误差比较大,是因为预处理有问题还是因为训练函数选择有问题?谢谢大家
[ 本帖最后由 eight 于 2007-7-2 19:37 编辑 ]
页:
[1]