How can i predict data by using neural network from input after fitting the data??
显示 更早的评论
I used Neural Network fitting tool for training my data and got outputs for each target that i supplied to the network. Those outputs are well within the error range and give a good fit for the network. But, now i want to predict output based on input samples not included within the data set that i previously provided to the nnftool for getting the outputs. Please tell me how i can do that? The input samples are withing the training set range.
3 个评论
sidra muqaddas
2016-10-26
x = [0 1 0; 0 1 0; 1 1 0; 1 1 1; 0 1 1; 1 1 1; 0 1 1; 1 1 0]; % three samples from input training data t = [0 0 1; 1 0 0 ; 0 1 0; 0 0 0;0 0 0;0 0 0]; %three samples from target training data [ni N]=size(x); % ni= no of input neurons [no N]=size(t); %no= no of output neurons nh=8; % no of hidden neurons in hidden layer wih = 0.01*randn(nh,ni+1); %weight matrix (iput to hidden layer) who = 0.01*randn(no,nh+1); %weight matrix (hidden to output layer) c = 0; while(c < 1000) c = c+1;
for i=1:N
for j = 1:nh
netj(j) = wih(j,1:end-1)*x(:,i)+wih(j,end);
outj(j) = tansig(netj(j));
end
for k = 1:no
netk(k) = who(k,1:end-1)*outj' + who(k,end);
outk(k) = 1./(1+exp(-netk(k)));
delk(k) = outk(k)*(1-outk(k))*(t(k,i)-outk(k));
end
%back propagation
for j = 1:nh
s=0;
for k = 1:no
s = s + who(k,j)*delk(k);
end
delj(j) = outj(j)*(1-outj(j))*s;
end
for k = 1:no
for l = 1:nh
who(k,l) = who(k,l)+.5*delk(k)*outj(l);
end
who(k,l+1) = who(k,l+1)+1*delk(k)*1;
end
for j = 1:nh
for ii = 1:ni
wih(j,ii) = wih(j,ii)+.5*delj(j)*x(ii,i);
end
wih(j,ii+1) = wih(j,ii+1)+1*delj(j)*1;
end
end
end
h = tansig(wih*[x;ones(1,N)]);
y = logsig(who*[h;ones(1,N)]); y=round(y); e = t-y; % new iput to the network csr=[0 1 0 0 0 0 1 0]; % current sensor reading
i need to add more training samples. right now my question is how to predict the corresponding output for csr
sidra muqaddas
2016-10-26
how to predict output from a new input,after you have done with the training.(using code not nntoolbox variables)
sidra muqaddas
2016-10-26
x = [0 1 0; 0 1 0; 1 1 0; 1 1 1; 0 1 1; 1 1 1; 0 1 1; 1 1 0]; % three samples from input training data
t = [0 0 1; 1 0 0 ; 0 1 0; 0 0 0;0 0 0;0 0 0]; %three samples from target training data
[ni N]=size(x); % ni= no of input neurons
[no N]=size(t); %no= no of output neurons
nh=8; % no of hidden neurons in hidden layer
wih = 0.01*randn(nh,ni+1); %weight matrix (iput to hidden layer)
who = 0.01*randn(no,nh+1); %weight matrix (hidden to output layer)
c = 0;
while(c < 1000)
c = c+1;
for i=1:N
for j = 1:nh
netj(j) = wih(j,1:end-1)*x(:,i)+wih(j,end);
outj(j) = tansig(netj(j));
end
for k = 1:no
netk(k) = who(k,1:end-1)*outj' + who(k,end);
outk(k) = 1./(1+exp(-netk(k)));
delk(k) = outk(k)*(1-outk(k))*(t(k,i)-outk(k));
end
%back propagation
for j = 1:nh
s=0;
for k = 1:no
s = s + who(k,j)*delk(k);
end
delj(j) = outj(j)*(1-outj(j))*s;
end
for k = 1:no
for l = 1:nh
who(k,l) = who(k,l)+.5*delk(k)*outj(l);
end
who(k,l+1) = who(k,l+1)+1*delk(k)*1;
end
for j = 1:nh
for ii = 1:ni
wih(j,ii) = wih(j,ii)+.5*delj(j)*x(ii,i);
end
wih(j,ii+1) = wih(j,ii+1)+1*delj(j)*1;
end
end
end
h = tansig(wih*[x;ones(1,N)]);
y = logsig(who*[h;ones(1,N)]); y=round(y); e = t-y; % new iput to the network csr=[0 1 0 0 0 0 1 0]; % current sensor reading
采纳的回答
更多回答(1 个)
Greg Heath
2014-6-28
2 个投票
newoutput = net(newinput)
THank you for formally accepting my answer
Greg
4 个评论
Atiyo Banerjee
2014-6-28
Greg Heath
2014-6-29
You still seem confused. Please reread what I have written about overfitting degrading generalization (the ability to perform well on nontraining data).
It is better to try to minimize the number of hidden nodes subject to the constraint that the MSE is no greater than a specified value like 0.01*Ndof^MSE00a/Ntrneq.
I have posted tens of examples. Most use a double loop approach designing ~10 separate random weight-initialization and data-division designs for each value of ~ 10 values of H that are considered. Try searching
greg fitnet Hub Ntrials
for details. Note that
Ntrneq ~ 0.7*150 = 105
Nw = (4+1+1)*12+1 = 73 > Ntrneq/2
Hope this helps.
Greg
Atiyo Banerjee
2014-7-5
Greg Heath
2016-10-26
You can always superimpose output plots (red) over target plots (blue) to obtain a better understanding of what causes errors.
类别
在 帮助中心 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!