How to make my output binary in pattern recognition ANN?
Afficher commentaires plus anciens
Hi,
I have a code for a pattern recognition ANN. The output is binary with 0 and 1 or 1 and 0 (two answers). The results of the model are not 0 and 1; they are decimal numbers (for example 0.3 and 0.6). How do I make my model outputs 0 and 1?
Here is the code:
x = It;
t = Ot;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% This is the section of code that creates the layers. It is a shallow network because there is only 1 hidden layer
% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize, trainFcn);
% You can turn this into a deep learning network by adding more hidden layers. For example, this code would create a 3-layer network.
% Three hidden layer NN
hiddenLayerSize1 = 15;
hiddenLayerSize2 = 20;
hiddenLayerSize3 = 20;
hiddenLayerSize4 = 20;
hiddenLayerSize5 = 20;
hiddenLayerSize6 = 20;
hiddenLayerSize7 = 20;
hiddenLayerSize8 = 20;
hiddenLayerSize9 = 20;
net = patternnet([hiddenLayerSize1 hiddenLayerSize2 hiddenLayerSize3 hiddenLayerSize4 hiddenLayerSize5 hiddenLayerSize6 hiddenLayerSize7 hiddenLayerSize8 hiddenLayerSize9], trainFcn);
% Setup 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,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Pattern Recognition dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!