Clear Filters
Clear Filters

Display probability/certainty of classification model

18 views (last 30 days)
Hello there,
I have trained a classification model with the function fitcdiscr() and fitcnet() and would like to get an output of the certainty (in %) of every prediction made by my model. So basically how convinced my model is that the given datapoint can be classified in the predicted class.
Thanks in advance for your help.

Answers (1)

Vishnu
Vishnu on 12 Jul 2023
Hi Jan,
To obtain the certainty or confidence level of predictions made by a classification model trained using the fitcdiscr() or fitcnet() functions, you can use the predict() function with the 'Posterior' option.
Below code is an example of how you can use the predict() function to obtain the certainty of predictions:
% Train your classification model using fitcdiscr() or fitcnet()
model = fitcdiscr(X, Y);
% Make predictions on new data
X_new = [prediction, ~, posterior] = predict(model, X_new, 'Posterior', true);
% Get the certainty (in %) for each prediction
certainty = max(posterior, [], 2) * 100;
% Display the certainty for each prediction
disp(certainty);
X represents the training data features, Y represents the corresponding class labels, and X_new represents the new data on which you want to make predictions.
The predict() function returns the predicted class labels in the prediction variable and the posterior probabilities of each class in the posterior variable.
  2 Comments
Jan
Jan on 12 Jul 2023
Hi Vishnu,
thanks for the quick response! When I try to implement your suggestion I simply recieve the Error:
"using classreg.learning.classif/CompactClassificationDiscriminant/predict
Too many input arguments."
How can I solve this issue?
Regards Jan
Jan
Jan on 12 Jul 2023
[pre, ~, pst] = predict(model,Testdata, 'Posterior', true);

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!