如果有2个输入(X1
和X2
)和1个目标输出(t
)由神经网络估算(每个节点有6个样本):
X1 = [2.765405915 2.403146899 1.843932529 1.321474515 0.916837222 1.251301467];
X2 = [84870 363024 983062 1352580 804723 845200];
t = [-0.12685144347197 -0.19172223428950 -0.29330584684934 -0.35078062276141 0.03826908777226 0.06633047875487];
我试图通过手动使用多元线性回归(普通最小二乘法或OLS)来找到t
预测的最佳拟合,结果非常好。
我打算从这个等式中找到a,b,c(回归系数):
t = a + b*X1 + c*X2
由于方程是具有两个回归量的多元线性回归方程的基本形式,当然我可以通过OLS找到a,b,c的值。
问题是:我试图通过使用神经网络(使用MATLAB nftool
并通过Levenberg-Marquardt反向传播或lmtrain
)训练它来找到回归系数但是不知道如何找到它们,虽然结果显示的错误少于OLS。
然后,出现了几个问题:
如果您有任何想法如何解决,请帮忙。我真的需要你的帮助!
这是由MATLAB nftool
生成的脚本,我曾用它来适应输出估计:
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by NFTOOL
% Created Fri Jun 05 06:26:36 ICT 2015
%
% This script assumes these variables are defined:
%
% x - input data.
% t - target data.
x = [2.765405915 2.403146899 1.843932529 1.321474515 0.916837222 1.251301467; 84870 363024 983062 1352580 804723 845200];
t = [-0.12685144347197 -0.19172223428950 -0.29330584684934 -0.35078062276141 0.03826908777226 0.06633047875487];
inputs = x;
targets = t;
% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 90/100;
net.divideParam.valRatio = 5/100;
net.divideParam.testRatio = 5/100;
% Train the Network
[net,tr] = train(net,inputs,targets);
% Test the Network
outputs = net(inputs);
errors = gsubtract(targets,outputs);
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(net,inputs,targets)
%figure, plotregression(targets,outputs)
%figure, ploterrhist(errors)
答案 0 :(得分:2)
A neural network will generally not find or encode a formula like t = a + b*X1 + c*X2
, unless you built a really simple one with no hidden layers and linear output. If you did then you could read the values [a,b,c]
from the weights attached to bias, input 1 and input 2. However, such a network offers no advantage over linear regression (essentially it is linear regression using NN tools to build it and comparatively slow gradient descent to find the lowest least-square error when it can be done in a single pass in OLS).
What you have built instead is a more complex non-linear function. Most likely the error is low because you have over-fit your data, which is very easy to do with a neural net. With your input data as shown, it should be possible to get an training error of 0, but that is not as good as it seems - it just means the neural network has found a complex surface that connects all your examples, which is probably of limited use as a predictive model.