Home / 🚀 Probability Theory & Odds/ Confusion Matrix Calculator

Confusion Matrix Calculator

Print Page
Confusion Matrix Table
Predicted Pos
Predicted Neg
Actual Pos
40 TP
2 FN
Actual Neg
8 FP
50 TN
Statistical Metrics
Accuracy (Acc): -
Sensitivity (Recall / TPR): -
Specificity (TNR): -
Precision (PPV): -
F1-Score: -
False Positive Rate (FPR): -
Matthews Correlation (MCC): -
Total Population (N): -
Calculated Steps & Math
Insert values.

A Confusion Matrix Calculator (also known as an Error Matrix Calculator, Classification Performance Metrics Utility, Machine Learning Evaluator, or Sensitivity-Specificity Calculator) calculates all 14+ standard binary and multi-class classification performance metrics from raw count values: True Positives (TP), True Negatives (TN), False Positives (FP – Type I Error), and False Negatives (FN – Type II Error). Whether you are evaluating artificial intelligence neural networks, medical cancer screening diagnostic accuracy, fraud detection algorithms, or natural language processing classifiers, a confusion matrix calculator provides a complete mathematical audit beyond simple accuracy.

Simple accuracy can be severely misleading on imbalanced datasets (e.g. predicting a rare 1% disease by always guessing “No Disease” yields 99% raw accuracy but 0% recall). A confusion matrix evaluates Precision, Recall (Sensitivity), Specificity, F1-Score, Balanced Accuracy, and the Matthews Correlation Coefficient (MCC) to reveal true model performance.

Our free online Confusion Matrix Calculator provides instant calculations across all standard classification evaluation metrics:

  • Overall Accuracy: Accuracy = (TP + TN) ÷ (TP + TN + FP + FN).
  • Precision (Positive Predictive Value – PPV): Precision = TP ÷ (TP + FP).
  • Recall (Sensitivity / True Positive Rate – TPR): Recall = TP ÷ (TP + FN).
  • Specificity (True Negative Rate – TNR): Specificity = TN ÷ (TN + FP).
  • F1-Score (Harmonic Mean of Precision & Recall): F1 = 2 · (Precision · Recall) ÷ (Precision + Recall) = 2TP ÷ (2TP + FP + FN).
  • Matthews Correlation Coefficient (MCC): MCC = [ (TP · TN) - (FP · FN) ] ÷ √[ (TP + FP)(TP + FN)(TN + FP)(TN + FN) ].

Master 2×2 Confusion Matrix Layout & Classification Metrics Table

The table below displays the exact 2×2 grid layout, mathematical formulas, and ideal target ranges for all primary classification metrics:

Classification Metric Name Mathematical Formula What It Measures & Focus Area Ideal Score Range Primary Real-World Use Case
Overall Accuracy (TP + TN) ÷ N Percentage of total predictions that were correct 0.0 to 1.0 (100%) Balanced class distributions
Precision (PPV) TP ÷ (TP + FP) Of all positive predictions, how many were actually positive? 0.0 to 1.0 (100%) Spam filters, fraud alerts (minimize False Positives)
Recall (Sensitivity / TPR) TP ÷ (TP + FN) Of all actual positives, how many did the model detect? 0.0 to 1.0 (100%) Medical diagnosis, cancer screening (minimize False Negatives)
Specificity (TNR) TN ÷ (TN + FP) Of all actual negatives, how many were correctly identified? 0.0 to 1.0 (100%) Healthy patient verification
F1-Score (Harmonic Mean) 2 · (P · R) ÷ (P + R) Balanced trade-off between Precision and Recall 0.0 to 1.0 (1.0 = Perfect) Imbalanced dataset standard metric
Matthews Correlation Coefficient (MCC) (TP·TN - FP·FN) ÷ √[&dots;] Gold standard correlation metric considering all 4 matrix cells equally -1.0 to +1.0 (+1 = Perfect) Bioinformatics & extreme class imbalance
False Positive Rate (FPR / Fall-out) FP ÷ (FP + TN) = 1 - Spec Proportion of negatives wrongly flagged as positive 0.0 (0% = Ideal) ROC Curve X-axis metric

Step-by-Step AI Cancer Screening Benchmark Example

To evaluate an AI cancer diagnostic screening model tested on 1,000 patients with True Positives TP = 85, True Negatives TN = 880, False Positives FP = 20, and False Negatives FN = 15:

Step 1 (Total Sample Size N): N = 85 + 880 + 20 + 15 = 1,000 patients

Step 2 (Calculate Overall Accuracy): Accuracy = (85 + 880) ÷ 1,000 = 965 ÷ 1,000 = 0.9650 = 96.50%

Step 3 (Calculate Precision PPV): Precision = 85 ÷ (85 + 20) = 85 ÷ 105 = 0.809524 = 80.95%

Step 4 (Calculate Recall / Sensitivity): Recall = 85 ÷ (85 + 15) = 85 ÷ 100 = 0.8500 = 85.00%

Step 5 (Calculate Specificity TNR): Specificity = 880 ÷ (880 + 20) = 880 ÷ 900 = 0.977778 = 97.78%

Step 6 (Calculate F1-Score): F1 = 2 × (0.809524 × 0.8500) ÷ (0.809524 + 0.8500) = 1.37619 ÷ 1.659524 = 0.829268 ≈ 82.93%

Step 7 (Calculate Matthews Correlation Coefficient MCC):

Numerator = (85 × 880) - (20 × 15) = 74,800 - 300 = 74,500

Denominator = √[ (105) × (100) × (900) × (895) ] = √[ 8,457,750,000 ] = 91,966.03

MCC = 74,500 ÷ 91,966.03 = +0.810082 ≈ +0.8101 (Strong positive correlation).

Thus, while the model boasts 96.50% raw accuracy, its true performance on cancer detection is captured by an 82.93% F1-score and +0.8101 MCC.


Type I Errors (False Positives) vs. Type II Errors (False Negatives)

Below is a comparative reference chart detailing the real-world trade-offs between Type I and Type II classification errors:

Error Metric Type I Error (False Positive FP) Type II Error (False Negative FN)
Statistical Definition Rejecting a true null hypothesis (False Alarm) Failing to reject a false null hypothesis (Missed Detection)
Medical Analogy Telling a healthy patient they have a disease Telling a sick patient they are healthy (Dangerous!)
Spam / Fraud Analogy Sending an important email to the spam folder Letting a fraudulent transaction pass through
Associated Optimization Metric Maximize Precision (PPV) Maximize Recall / Sensitivity (TPR)

History & Mathematics: 1904 Karl Pearson to 1975 Brian Matthews

1904 Karl Pearson & 2×2 Contingency Tables

Formulated by English statistician Karl Pearson in 1904, 2 × 2 contingency tables introduced systematic evaluation of cross-tabulated categorical variables, establishing the foundation for cross-classification errors.

1975 Brian Matthews & The Matthews Correlation Coefficient (MCC)

In 1975, biochemist Brian W. Matthews introduced the MCC metric to evaluate protein secondary structure prediction algorithms. MCC is widely recognized as the single most reliable binary classification metric because it produces a high score only if the model predicts well in all four confusion matrix quadrants.


Popular direct tools:


Frequently Asked Questions (FAQ)

What is a Confusion Matrix in Machine Learning?

A Confusion Matrix is a tabular layout that summarizes the performance of a classification model by comparing actual ground-truth labels against predicted labels across four categories: True Positives (TP), True Negatives (TN), False Positives (FP), and False Negatives (FN).

Why is F1-Score better than Accuracy for imbalanced data?

Accuracy includes True Negatives, which can inflate scores on imbalanced datasets (e.g. 99% negative cases). The F1-Score focuses strictly on Precision and Recall, ignoring True Negatives to measure performance on the minority positive class.

What is a good Matthews Correlation Coefficient (MCC) score?

MCC ranges from -1.0 (total disagreement) to +1.0 (perfect prediction). A score of 0.0 indicates random guessing, while scores above +0.70 represent strong classification performance.