how to rewrite this for feedforward neural network for with 52 inputs and 2 output that predict emission rate not for digits, where i get an error of In an assignment A(:) = B, the number of elements in A and B must be the same. Error in line36

2 次查看(过去 30 天)
sweep=[3,5:5:50]; %parameter values to test
scores=zeros(length(sweep),1); %pre-allcation
models=cell(length(sweep),1); %pre-allcation
load('inputs.mat');
load('outputs.mat');
load('newinputs.mat');
load('newoutputs.mat');
in=inputs; % loads inputs into variable 'in'
t=outputs; % loads outputs into variable 't'
in_test=newinputs; % loads test inputs into variable 'in_test'
t_test=newoutput; % loads test inputs into variable 't_test'
%training function:
net.trainFcn = 'trainlm';
%transfer functions:
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'purelin';
net.trainParam.epochs = 100000;
for i=1:length(sweep)
hiddenlayersize=sweep(i); %number of hidden layer neurons
net=patternnet(hiddenlayersize);
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio=0.7;
net.divideParam.valRatio=0.15;
net.divideParam.testRatio=0.15;
%training the network
net = train(net,in,t);
%simulating the outputs
y=sim(net,in);
%store the trained network
models{i}=net;
%prediction to test the network
pre=net(in_test);
%prediction labels
scores(i)=sum(t_test==pre)/length(t_test); %accuracy
end
%plot accuracy versus number of neorons in the hidden layer
figure
plot(sweep,scores,'.-')
xlabel('number of hidden neurons')
ylabel('accuracy')
title('number of hidden neurons vs.accuracy')

回答(2 个)

Greg Heath
Greg Heath 2018-12-30
编辑:Greg Heath 2019-1-3
Replace the " == " in
scores(i)=sum(t_test==pre)/length(t_test); %accuracy
with a minus sign
WHOOPS !!!
I misread the text. I was thinking of an error measure to minimize of the form
errorscore(i) = sum( abs( t_test - pre )/ length(t_test) )
Hope this helps.
*Thank you for formally accepting my answer*
Greg

Reff
Reff 2020-4-19
hi,
what is means of paramater?
  1. sweep=[3,5:5:50]; %parameter values to test
  2. scores=zeros(length(sweep),1); %pre-allcation
  3. models=cell(length(sweep),1); %pre-allcation

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by