Azzera filtri
Azzera filtri

Display probability/certainty of classification model

18 visualizzazioni (ultimi 30 giorni)
Jan
Jan il 12 Lug 2023
Commentato: Jan il 12 Lug 2023
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.

Risposte (1)

Vishnu
Vishnu il 12 Lug 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 Commenti
Jan
Jan il 12 Lug 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 il 12 Lug 2023
[pre, ~, pst] = predict(model,Testdata, 'Posterior', true);

Accedi per commentare.

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by