Calculate TP FP TN FN in Python

Paste actual and predicted labels for quick checks. Review confusion counts and key model scores. Export clear files and inspect Python style output now.

Calculator

Use one label per line, or separate labels with commas.

Example data table

Row Actual Predicted Positive label Expected type
1111TP
2011FP
3001TN
4101FN

Formula used

TP counts rows where actual equals the positive label and predicted equals the positive label.

FP counts rows where actual is not positive, but predicted is positive.

TN counts rows where actual is not positive and predicted is not positive.

FN counts rows where actual is positive, but predicted is not positive.

Accuracy = (TP + TN) / (TP + FP + TN + FN).

Precision = TP / (TP + FP). Recall = TP / (TP + FN). Specificity = TN / (TN + FP).

F1 Score = 2TP / (2TP + FP + FN). Balanced Accuracy = (Recall + Specificity) / 2.

Python logic

tp = sum(1 for a, p in zip(actual, predicted) if a == positive and p == positive)
fp = sum(1 for a, p in zip(actual, predicted) if a != positive and p == positive)
tn = sum(1 for a, p in zip(actual, predicted) if a != positive and p != positive)
fn = sum(1 for a, p in zip(actual, predicted) if a == positive and p != positive)

How to use this calculator

  1. Select label list mode when you have actual and predicted values.
  2. Paste the actual labels into the first text area.
  3. Paste predicted labels in the same order into the second text area.
  4. Enter the positive label exactly as it appears in your data.
  5. Use direct count mode when TP, FP, TN, and FN are already known.
  6. Press calculate, then download CSV or PDF when needed.

Understanding TP FP TN FN

A binary classifier compares actual labels with predicted labels. Four counts summarize every decision. True positives are positive cases predicted as positive. False positives are negative cases predicted as positive. True negatives are negative cases predicted as negative. False negatives are positive cases predicted as negative. These counts matter more than one score, because each count explains a different kind of success or error.

Why this calculator helps

This calculator accepts label lists, then builds the same confusion matrix you would create with Python logic. It also accepts direct counts when you already have a matrix. The tool checks list length, trims empty items, and can ignore letter case. It reports accuracy, precision, recall, specificity, F1 score, negative predictive value, false positive rate, false negative rate, and balanced accuracy. These measures give a wider view of model behavior.

Interpreting the results

Accuracy shows the share of all correct predictions. Precision answers how often a predicted positive was correct. Recall answers how many real positives were found. Specificity answers how many real negatives were avoided correctly. F1 balances precision and recall, so it helps when classes are uneven. Balanced accuracy averages recall and specificity, which is helpful when negatives outnumber positives.

Practical workflow

Paste the actual labels in the first box. Paste predicted labels in the second box. Use one label per line, or separate values with commas. Enter the exact positive label, such as 1, yes, fraud, spam, or pass. Submit the form and review the confusion counts first. Then compare the derived metrics. Export CSV for spreadsheets. Export the simple PDF for reports. Keep a copy of the example table for testing. For Python projects, match the same positive label before checking final metrics.

Common mistakes to avoid

Do not mix positive labels across files. A value of true is not the same as 1 unless you convert it first. Check missing rows before pasting labels. A shifted row can change every count after that point. Review false positives and false negatives separately, because their business costs can differ. In medical screening, a false negative may be serious. In email filtering, a false positive may hide important messages. Use consistent labels for every run.

FAQs

What does TP mean?

TP means true positive. It counts positive cases that the model also predicted as positive. For example, an actual spam email predicted as spam is a true positive.

What does FP mean?

FP means false positive. It counts negative cases predicted as positive. In a spam model, a normal email predicted as spam would be a false positive.

What does TN mean?

TN means true negative. It counts negative cases that the model predicted as negative. This shows how well the model avoids unwanted positive alerts.

What does FN mean?

FN means false negative. It counts positive cases predicted as negative. These errors can be costly when missed positives are important.

Can I use words instead of 1 and 0?

Yes. You can use labels like yes, no, spam, ham, pass, fail, fraud, or normal. Enter the positive label exactly.

Why must both label lists have the same length?

Each actual value must match one predicted value. If list lengths differ, rows cannot be compared safely, so the confusion counts may be wrong.

Which metric should I check first?

Start with TP, FP, TN, and FN. Then review precision and recall. Accuracy alone may hide weak performance on imbalanced data.

Does case sensitivity matter?

It matters when labels use different capital letters. Keep case sensitivity off for simple matching. Turn it on when Case, case, and CASE must differ.

Related Calculators

Paver Sand Bedding Calculator (depth-based)Paver Edge Restraint Length & Cost CalculatorPaver Sealer Quantity & Cost CalculatorExcavation Hauling Loads Calculator (truck loads)Soil Disposal Fee CalculatorSite Leveling Cost CalculatorCompaction Passes Time & Cost CalculatorPlate Compactor Rental Cost CalculatorGravel Volume Calculator (yards/tons)Gravel Weight Calculator (by material type)

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.