BP神经网络与MATLAB实现案例二

**

欢迎来的菜市场!!!

**
你现在手里有一袋子鸡腿(j),一袋子葡萄(t),要去换人家的西瓜(h)
假设鸡腿20元/斤,葡萄17元/斤,西瓜2元/斤
也就是h=(20j+17t)/2
当然我们要通过机器去实现它
给出一组数据

BP神经网络与MATLAB实现案例二_第1张图片
让我们对她进行一系列的代码化

[input,ps1]=mapminmax([j;t]);
[target,ps2]=mapminmax(hh); 


net=newff(input,target,6,{'tansig','purelin'},'trainlm');
net.trainParam.epochs=10000;
net.trainParam.goal=0.01;
net.trainParam.lr=0.001;
net=train(net,input,target);



jj=[3 2 4 1 2 5 4 3]; %鸡腿
tt=[5 4 1 2 3 2 3 1];%葡萄
hhh=(20*j+17*t)/3;%西瓜
input1=mapminmax('apply',[jj;tt],ps1);%应用之前的种子归一化



%预测
yuce=net(input1);
bagezhi=mapminmax('reverse',yuce,ps2);

set(0,'defaultfigurecolor','w')
figure
plot(hhh,'*','color',[222 87 18]/255);hold on
plot(bagezhi,'-o','color',[244 208 0]/255,...
'linewidth',2,'MarkerSize',14,'MarkerEdgecolor',[138 151 123]/255);
legend('act','yuce')
xlabel('大西瓜大西瓜大西瓜'),ylabel('斤')
set(gca, 'Box', 'off', 'TickDir', 'out', 'TickLength', [.02 .02], ...
    'XMinorTick', 'on', 'YMinorTick', 'on', 'YGrid', 'on', ...
    'XColor', [.3 .3 .3], 'YColor', [.3 .3 .3],'LineWidth', 1)

结果如下
BP神经网络与MATLAB实现案例二_第2张图片
BP神经网络与MATLAB实现案例二_第3张图片
3步就到达了期望误差
BP神经网络与MATLAB实现案例二_第4张图片
下面给出圈圈中的预测值的数据和准确值
1.预测数据
这里写图片描述
2.准确值
BP神经网络与MATLAB实现案例二_第5张图片
一眼便知,误差很小,训练理想,预测较准确
再来看看Validation和test
BP神经网络与MATLAB实现案例二_第6张图片
拟合的较为合理,且两个图的点没有出现较少的情况,能说明问题

好了,麻麻再也不用担心我该换回几斤的西瓜了!

你可能感兴趣的:(神经网络)