Output threshold function, Neural Network

5 次查看(过去 30 天)
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)

回答(1 个)

Jayanti
Jayanti 2025-7-3
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.

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by