How to add one specific condition in my trained Neural Network

조회 수: 2(최근 30일)
Dear all,
I have 3 types of condition in my Neural Network (662790, 667606, 672067) as you can see in the image below:
I used 3s vector of data for each type to create the FeatureTable and the trainedmodel. I am attaching both variable.
I would like the trainedmodel to identify my new data as type 662790, 667606 or 672067 just if is really similar(95% for example) if the new data (new table feature) that I will process is not similar, I would like to be recognized as 0 (zero). The reason for that is that I have sometimes a vector that is just constant 5 (or any other number of function that is create not one of this 3 real type) and at the moment my trained model will recognize as one of the 3 types what is wrong. I wanna all this data, that are clear not my time to be recognized as type 0.
This type zero will be everything that is not 95% similar from my 3 main type.
What shloud i change in my trainedmodel to implement this idea.
Thanks in advance.


Shivam Singh
Shivam Singh 2021년 12월 6일
Hello Yogan,
My understanding is that you have a trained 3-class classifier and you want to put a threshold on the activation of last layer of the model to classify the output in the 4th class, if maximum activation score is less than the provided threshold.
For doing so, you may access the scores of the final layer of “ClassificationNeuralNetwork” object using predict function. Then, you may obtain the maximum score and put a threshold check on that. You may refer to the following example:
clc; clear all; close all;
load trainedModel.mat
load FeatureTable1.mat
%In the inputVector, you can provide the test input Sample
inputVector = [4.97,4.98,1.007,0.406];
[outputClass, scores] = predict (Mdl,inputVector);
maxScore = max(scores);
% "0" is the fourth class
outputPredictedClassName ="0”;
thresholdForQualificationIntoPredifinedClasses = 0.95;
if (maxScore > thresholdForQualificationIntoPredifinedClasses)

Community Treasure Hunt

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

Start Hunting!

Translated by