# Confusion matrix / Matching matrix along with Precision, Sensitivity, Specificity and Model Accuracy (Scripts) 1.0

Average Rating
User Rating:
Visitors Rating:
My rating:

See full specifications

## Confusion matrix / Matching matrix along with Precision, Sensitivity, Specificity and Model Accuracy (Scripts) Publisher's description

### function [confmatrix] = cfmatrix2(actual, predict, classlist, per, printout)

function [confmatrix] = cfmatrix2(actual, predict, classlist, per, printout)

CFMATRIX2 calculates the confusion matrix for any prediction algorithm ( prediction algorithm generates a list of classes to which each test feature vector is assigned );

Outputs:

Confusion matrix

Also the TP, FP, FN and TN are output for each class based on

http://en.wikipedia.org/wiki/Confusion_matrix

The Precision, Sensitivity and Specificity for each class have also been added in this update along with the overall accuracy of the model.

% Further description of the outputs:
%
% True Postive [TP] = Condition Present + Positive result
% False Positive [FP] = Condition absent + Positive result [Type I error]
% False (invalid) Negative [FN] = Condition present + Negative result [Type II error]
% True (accurate) Negative [TN] = Condition absent + Negative result
% Precision(class) = TP(class) / ( TP(class) + FP(class) )
% Sensitivity(class) = Recall(class) = TruePositiveRate(class)
% = TP(class) / ( TP(class) + FN(class) )
% Specificity ( mostly used in 2 class problems )=
% TrueNegativeRate(class)
% = TN(class) / ( TN(class) + FP(class) )
%
% Inputs:
%
% 1. actual / 2. predict
The inputs provided are the 'actual' classes vector and the 'predict'ed classes vector. The actual classes are the classes to which the input feature vectors belong. The predicted classes are the class to which the input feature vectors are predicted to belong to, based on a prediction algorithm. The length of actual class vector and the predicted class vector need to be the same. If they are not the same, an error message is displayed.
% 3. classlist
The third input provides the list of all the classes {p,n,...} for which the classification is being done. All classes are numbers.
% 4. per = 1/0 (default = 0)
This parameter when set to 1 provides the values in the confusion matrix as percentages. The default provides the values in numbers.
% 5. printout = 1/0 ( default = 1 )
This parameter when set to 1 provides output on the matlab terminal and can be used to suppress output by setting to 0 ( default = 1 ). Assuming 'printout' of output use case would be more common and at the same time provided option to suppress output when the number of classes can be very large.

% Example:
% >> a = [ 1 2 3 1 2 3 1 1 2 3 2 1 1 2 3];
% >> b = [ 1 2 3 1 2 3 1 1 1 2 2 1 2 1 3];
% >> Cf = cfmatrix2(a, b, [1 2 3], 0, 1);
% is equivalent to
% >> Cf = cfmatrix2(a, b);
% The values of classlist(unique from actual), per(0), printout(1) are set
% to the respective defaults.
%
%

% a. Pre-initialize confmatrix
% b. Simplified logic making the code more readable and faster (based on comments from an interviewer who reviewed the code)
% c. Provide input variable 'printout' as an option to suppress output to screen ( output to display is still the default (printout = 1) assuming that will be the more common use case ).
% d. Added Precision(class), Sensitivity(class), Specificity(class) and the overall accuracy of model calculations

#### System Requirements:

No special requirements.
Program Release Status: Minor Update
Program Install Support: Install and Uninstall

#### Confusion matrix / Matching matrix along with Precision, Sensitivity, Specificity and Model Accuracy (Scripts) Tags:

Click on a tag to find related softwares

## Most Popular

ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation