BP 神经网络进行回归拟合后,如何进行数据预测。
Show older comments
MATLAB新手,刚刚网课学习到BP神经网络的回归拟合,用回归拟合后,如何代入进行下一数据的预测
matlab版本R2019B
以下为完成回归拟合代码。
clear
clc
导入数据
load practice_data.mat
随机产生训练集和测试集
temp = randperm(size(NIR,1));
训练集——50个样本
P_train = NIR(temp(1:50),:)';
T_train = octane(temp(1:50),:)';
测试集——10个样本
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
error = abs(T_sim - T_test)./T_test;
决定系数R^2
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('真实值','预测值')
xlabel('预测样本')
ylabel('商家需求值')
string = {'测试集商家需求值含量预测结果对比';['R^2=' num2str(R2)]};
title(string)
坐到目前为止,不知如何进行预测
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!