Output threshold function, Neural Network

5 Ansichten (letzte 30 Tage)
Aydin Ahmadli
Aydin Ahmadli am 2 Dez. 2018
Beantwortet: Jayanti am 3 Jul. 2025
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)

Antworten (1)

Jayanti
Jayanti am 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.

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by