matlab神经网络2:数据拟合

1.前文

    The following topics explain how to use graphical tools for training neural networks to solve problems in function fitting, pattern recognition, clustering, and time series. Using these tools can give us an excellent introduction to the use of the Neural Network
Toolbox software:
• “Fit Data with a Shallow Neural Network” 
• “Classify Patterns with a Shallow Neural Network” 
• “Cluster Data with a Self-Organizing Map” 
• “Shallow Neural Network Time-Series Prediction and Modeling” 

2.浅层神经网络进行数据拟合

2.1 GUI的方法

command-line:nnstart
matlab神经网络2:数据拟合_第1张图片
LOAD chemical_dataset.MAT loads these two variables:
chemicalInputs - a 8x498 matrix defining measurements taken from eight sensors during a chemical process.
chemicalTargets - a 1x498 matrix of a ninth sensor's measurements, to be estimated from the first eight.
A good estimator for the ninth sensor will allow it to be removed and estimations used in its place.
[X,T] = chemical_dataset loads the inputs and targets into variables of your own choosing.     
matlab神经网络2:数据拟合_第2张图片
Select a training algorithm, then click Train. Levenberg-Marquardt (trainlm) is recommended for most problems, but for some noisy and small problems Bayesian Regularization (trainbr) can take longer but obtain a better solution. For large problems, however, Scaled Conjugate Gradient (trainscg) is recommended as it uses gradient calculations which are more memory efficient than the Jacobian calculations the other two algorithms use. This example uses the default LevenbergMarquardt.

matlab神经网络2:数据拟合_第3张图片

The regression plots display the network outputs with respect to targets for training, validation, and test sets. For a perfect fit, the data should fall along a 45 degree line, where the network outputs are equal to the targets. For this problem, the fit is reasonably good for all data sets, with R values in each case of 0.93 or above. If even more accurate results were required, you could retrain the network by clicking Retrain in nftool. This will change the initial weights and biases of the network, and may produce an improved network after retraining. Other options are provided on the following










matlab神经网络2:数据拟合_第4张图片
The histogram can give you an indication of
outliers, which are data points where the fit is significantly worse than the majority of data. 
如果训练集误差比较大,应该是网络太小了,增加层数或者每层的神经元数;
如果测试集的误差比较大,应该就是过拟合。








利用工具箱生成自动生成代码:
matlab神经网络2:数据拟合_第5张图片

2.2 代码驱动

% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by NFTOOL
% houseInputs - input data.
% houseTargets - target data.
inputs = houseInputs;
targets = houseTargets;
% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
% Set up 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,inputs,targets);
% Test the Network
outputs = net(inputs);
errors = gsubtract(outputs,targets);
performance = perform(net,targets,outputs);
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
figure, plotperform(tr)
figure, plottrainstate(tr)
%figure, plotfit(targets,outputs)
figure, plotregression(targets,outputs)
figure, ploterrhist(errors)

你可能感兴趣的:(神经网络,深度学习,matlab)