MAT之NN:实现BP神经网络的回归拟合,基于近红外光谱的汽油辛烷值含量预测结果对比
目录
输出结果
实现代码
输出结果
![50dce0d0e68e49c622c827fdc83551cb.png](https://i-blog.csdnimg.cn/blog_migrate/48fe273bd98e873dc7b3e1f425e31c16.jpeg)
![289a6b23976183fc399ad7f13d4d2d39.png](https://i-blog.csdnimg.cn/blog_migrate/fc9ea06e90776b29d2cf7f101eea5d6d.png)
![b3cee06382b788e36384736fe9c067e7.png](https://i-blog.csdnimg.cn/blog_migrate/ed1656d09c0c104a8357470c9a4399ef.jpeg)
![289a6b23976183fc399ad7f13d4d2d39.png](https://i-blog.csdnimg.cn/blog_migrate/fc9ea06e90776b29d2cf7f101eea5d6d.png)
![d5f05226819bbf8438b4a656e66c4874.png](https://i-blog.csdnimg.cn/blog_migrate/8aa12ce9b004a7b187899ef92deff6db.jpeg)
![289a6b23976183fc399ad7f13d4d2d39.png](https://i-blog.csdnimg.cn/blog_migrate/fc9ea06e90776b29d2cf7f101eea5d6d.png)
![22b091bd0910307751deafb5e73ae819.png](https://i-blog.csdnimg.cn/blog_migrate/8a57a5d36f4bb03e4d5b213192e89b33.jpeg)
![289a6b23976183fc399ad7f13d4d2d39.png](https://i-blog.csdnimg.cn/blog_migrate/fc9ea06e90776b29d2cf7f101eea5d6d.png)
实现代码
load spectra_data.mat
plot(NIR')
title('Near infrared spectrum curve—Jason niu')
temp = randperm(size(NIR,1));
P_train = NIR(temp(1:50),:)';
T_train = octane(temp(1:50),:)';
P_test = NIR(temp(51:end),:)';
T_test = octane(temp(51:end),:)';
N = size(P_test,2);
[p_train, ps_input] = mapminmax(P_train,0,1);
p_test = mapminmax('apply',P_test,ps_input);
[t_train, ps_output] = mapminmax(T_train,0,1);
net = newff(p_train,t_train,9);
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-3;
net.trainParam.lr = 0.01;
net = train(net,p_train,t_train);
t_sim = sim(net,p_test);
T_sim = mapminmax('reverse',t_sim,ps_output);
error = abs(T_sim - T_test)./T_test;
R2 = (N * sum(T_sim .* T_test) - sum(T_sim) * sum(T_test))^2 / ((N * sum((T_sim).^2) - (sum(T_sim))^2) * (N * sum((T_test).^2) - (sum(T_test))^2));
result = [T_test' T_sim' error']
figure
plot(1:N,T_test,'b:*',1:N,T_sim,'r-o')
legend('Real value','predicted value')
xlabel('Prediction sample')
ylabel('Octane numbe')
string = {'Comparison of the prediction results of the octane number in the test set—Jason niu';['R^2=' num2str(R2)]};
title(string)
![289a6b23976183fc399ad7f13d4d2d39.png](https://i-blog.csdnimg.cn/blog_migrate/fc9ea06e90776b29d2cf7f101eea5d6d.png)
相关文章
MAT之NN:实现BP神经网络的回归拟合,基于近红外光谱的汽油辛烷值含量