How to show the accuracy on a confusion matrix
조회 수: 30 (최근 30일)
So I've trained a perceptron with 29 data and I implemented its confusion matrix. Yet I want it to show me the accuracy. So far it only appears as follows:
And this is the code that I used to plot it:
function katataksh= Ask31c (w1,w2,b,x_new,y_new)
W=[w1 w2 b]; %ορίζω τον πίνακα W να παίρνει τις τιμές των w1,w2 και b
accuracy=sum(y_new == katataksh,'all')/numel(katataksh);
Note that there's more code that is implemented, but I think it's not necessary to write it here, since I only want to find the accuracy of the confusion matrix.
Thank you in advance!
Chunru 2022년 4월 18일
You nee to add column and row summaries. Check out the following example from doc.
X = meas;
Y = species;
Mdl = fitcknn(X,Y,'NumNeighbors',5,'Standardize',1);
predictedY = resubPredict(Mdl);
cm = confusionchart(Y,predictedY);
% The confusion matrix displays the total number of observations in each cell.
% The rows of the confusion matrix correspond to the true class, and the columns
% correspond to the predicted class. Diagonal and off-diagonal cells correspond
% to correctly and incorrectly classified observations, respectively.
% By default, confusionchart sorts the classes into their natural order as defined
% by sort. In this example, the class labels are character vectors, so confusionchart
% sorts the classes alphabetically. Use sortClasses to sort the classes by a specified
% order or by the confusion matrix values.
% The NormalizedValues property contains the values of the confusion matrix. Display
% these values using dot notation.
% Modify the appearance and behavior of the confusion matrix chart by changing property
% values. Add a title.
cm.Title = 'Iris Flower Classification Using KNN';
% Add column and row summaries.
cm.RowSummary = 'row-normalized';
cm.ColumnSummary = 'column-normalized';