Output threshold function, Neural Network

조회 수: 23 (최근 30일)
Aydin Ahmadli
Aydin Ahmadli 2018년 12월 2일
답변: Jayanti 2025년 7월 3일
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