Output threshold function, Neural Network
6 views (last 30 days)
Show older comments
I am using neural network of 1 hidden layer with 2 neurons, 2 input neurons and 2 output neurons. My aim is to set output threshold such as if it is greater than >0.5, set output to 1, if less than <0.5, set output to 0. How can I do it? My code is below:
clc;
in=[0 0 1 1
1 0 0 1];
out=[1 1 1 0
0 1 0 1];
net=feedforwardnet(2);
net.layers{1}.transferFcn='logsig';
net.layers{2}.transferFcn='logsig';
net.trainParam.perf = 'sse';
net.trainParam.epochs = 100;
net.trainParam.goal = 1e-6;
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net = init(net);
[net,tr] = train(net, in, out)
0 Comments
Answers (1)
Jayanti
on 3 Jul 2025
Hi Aydin,
As you're training a feedforward neural network with 2 inputs, 1 hidden layer of 2 neurons, and 2 output neurons.
After training, the output of the network "net(in)" will be in the range (0, 1). To convert this into binary values (0 or 1) based on a threshold of 0.5, you can use the following code:
% Simulate the network
y = net(in);
% Apply thresholding
y_binary = double(y > 0.5);
This will interpret the network's output as binary classification results.
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!