Confusion Matrix Calculator

Enter TP, FP, FN, and TN values to instantly compute all classification metrics.

🔒100% Client-Side. Everything runs in your browser — no data is sent to any server.
Predicted PositivePredicted Negative
Actual Positive
TP (True Positive)
FN (False Negative)
Actual Negative
FP (False Positive)
TN (True Negative)
Accuracy
N/A
Precision
N/A
Recall (Sensitivity)
N/A
Specificity
N/A
F1 Score
N/A
F2 Score
N/A
NPV
N/A
MCC
N/A

What is a confusion matrix?

A confusion matrix is a table that summarizes the performance of a classification model by showing the counts of correct and incorrect predictions broken down by class. The four quadrants are: True Positive (TP) — model correctly predicts positive; True Negative (TN) — model correctly predicts negative; False Positive (FP) — model predicts positive but it is actually negative (Type I error); False Negative (FN) — model predicts negative but it is actually positive (Type II error).

Different metrics suit different problems: Precision matters for spam filters (you want few legitimate emails marked as spam). Recall matters for cancer screening (you want to miss as few real cases as possible). F1 Score is the harmonic mean of both and is the go-to metric for imbalanced datasets. MCC (Matthews Correlation Coefficient) is considered the most informative single metric for binary classification.

Confusion matrix in scikit-learn

from sklearn.metrics import ( confusion_matrix, classification_report, precision_score, recall_score, f1_score, matthews_corrcoef ) y_true = [1, 1, 1, 0, 0, 0, 1, 0, 1, 0] y_pred = [1, 1, 0, 0, 0, 1, 1, 0, 0, 0] cm = confusion_matrix(y_true, y_pred) tn, fp, fn, tp = cm.ravel() print(f"TP={tp}, TN={tn}, FP={fp}, FN={fn}") print(classification_report(y_true, y_pred)) print(f"MCC: {matthews_corrcoef(y_true, y_pred):.4f}")

When to use F1 vs Accuracy

Accuracy is misleading when classes are imbalanced. A model that always predicts the majority class achieves 99% accuracy on a dataset where only 1% of samples are positive — yet it has zero predictive power. In such cases, use F1 Score or MCC, which account for both false positives and false negatives. MCC is particularly robust because it considers all four cells of the confusion matrix and returns a value between −1 and +1, where +1 is a perfect prediction.