我正在尝试使用nprtool训练神经网络,并且还手动调用newpr和train方法。 我使用面向行的样本,而不是默认为列:
使用nprtool没有问题,但是当我调用自动生成的M文件时,输出是:
??? Error using ==> network.train at 145
Targets are incorrectly sized for network.
Matrix must have 24 columns.
Error in ==> create_pr_net at 29
[net,tr] = train(net,inputs,targets);
我的输入是140x24,我的目标是140x3。
Matlab生成的代码是:
function net = create_pr_net(inputs,targets)
%CREATE_PR_NET Creates and trains a pattern recognition neural network.
%
% NET = CREATE_PR_NET(INPUTS,TARGETS) takes these arguments:
% INPUTS - RxQ matrix of Q R-element input samples
% TARGETS - SxQ matrix of Q S-element associated target samples, where
% each column contains a single 1, with all other elements set to 0.
% and returns these results:
% NET - The trained neural network
%
% For example, to solve the Iris dataset problem with this function:
%
% load iris_dataset
% net = create_pr_net(irisInputs,irisTargets);
% irisOutputs = sim(net,irisInputs);
%
% To reproduce the results you obtained in NPRTOOL:
%
% net = create_pr_net(inputs,targets);
% Create Network
numHiddenNeurons = 2000; % Adjust as desired
net = newpr(inputs,targets,numHiddenNeurons);
net.divideParam.trainRatio = 90/100; % Adjust as desired
net.divideParam.valRatio = 5/100; % Adjust as desired
net.divideParam.testRatio = 5/100; % Adjust as desired
% Train and Apply Network
[net,tr] = train(net,inputs,targets);
outputs = sim(net,inputs);
% Plot
plotperf(tr)
plotconfusion(targets,outputs)
我正在使用Matlab R2010a。
感谢。
答案 0 :(得分:3)
如Matlab帮助文件中所述:
INPUTS - Q R元素输入样本的RxQ矩阵 TARGETS - Q S元素相关目标样本的SxQ矩阵
在手动调用Matlab训练函数之前,您可能需要输入和目标矩阵的转置。
Input = Input';
和
Taget = Target';