matlab神经网络工具箱
1.输入nftool;点击next
2.输入特征X 和目标值Y如下:【注意按行/按列】
3.设置训练集/验证集/测试机比例:【一般默认为0.7:0.15:0.15】
4.设置隐藏层个数:【需要调的参数之一】
5.选择优化算法:默认如图;点击train进行训练
6.生成图像:【如图plots】
6.1 performance
横坐标:训练结束时的epochs数【神经网络一次前向传播+一次反向传播=一个epoch】
纵坐标:均方误差
从图中可以得到:在epochs=5时,验证集valiadation和测试集test达到最小均方误差。
6.2 training state
横坐标:epoch
纵坐标:梯度gradient;mu?;val fail?;
梯度:若梯度为0,则为图像最低点,即最优位置
mu:
val fail:
【validation check=6:若连续六次训练,训练误差没有变小,则假定继续训练下去效果不会变好,停止训练。】
6.3 error histogram【误差直方图】
横坐标:误差区间的中位数;
纵坐标:位于该误差区间的样本个数
可以得到:神经网络的输出值与样本原目标值的误差;
6.4 regression【检验预测值和目标值的线性化程度?】
横坐标:样本原目标值;
纵坐标:神经网络输出预测值;
可以得到:原目标值和预测值的相关度;用系数R表示,若R越接近1,则表示线性化程度越高,结果越好。
7 另外添加更多的测试集
8.生成代&保存训练结果和网络
点击xx script,生成所需要的代码(m文件);
点击save results,将数据结果和网络输出到workspace;
9.生成代码如图所示:
% Solve an Input-Output Fitting problem with a Neural Network % Script generated by Neural Fitting app % Created 15-May-2020 10:45:36 % % This script assumes these variables are defined: % % XXnum - input data. % YYnum - target data. x = XXnum'; t = YYnum'; % Choose a Training Function % For a list of all training functions type: help nntrain % 'trainlm' is usually fastest. % 'trainbr' takes longer but may be better for challenging problems. % 'trainscg' uses less memory. Suitable in low memory situations. trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation. % Create a Fitting Network hiddenLayerSize = 10; net = fitnet(hiddenLayerSize,trainFcn); % Setup Division of Data for Training, Validation, Testing net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100; % Train the Network [net,tr] = train(net,x,t); % Test the Network y = net(x); e = gsubtract(t,y); performance = perform(net,t,y) % View the Network view(net) % Plots % Uncomment these lines to enable various plots. %figure, plotperform(tr) %figure, plottrainstate(tr) %figure, ploterrhist(e) %figure, plotregression(t,y) %figure, plotfit(net,x,t)
参考资料:
1.https://blog.csdn.net/ljyljyok/article/details/81362465 Lindsay.Lu,如何利用matlab做BP神经网络分析,
2. https://blog.csdn.net/weixin_44486547/article/details/93394970 晴松,初探MATLAB神经网络