Display probability/certainty of classification model

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

回答(1 个)

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by