True Positive Rate Calculation

.tpr-calculator-container { max-width: 800px; margin: 0 auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #333; line-height: 1.6; } .calc-box { background: #f9f9f9; border: 1px solid #e0e0e0; border-radius: 8px; padding: 25px; margin-bottom: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); } .calc-title { text-align: center; margin-bottom: 20px; color: #2c3e50; font-size: 24px; font-weight: 700; } .input-group { margin-bottom: 15px; } .input-group label { display: block; margin-bottom: 5px; font-weight: 600; color: #555; } .input-group input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; box-sizing: border-box; } .input-group input:focus { border-color: #3498db; outline: none; } .input-hint { font-size: 12px; color: #777; margin-top: 3px; } .calc-btn { display: block; width: 100%; background: #3498db; color: white; border: none; padding: 12px; font-size: 18px; font-weight: bold; border-radius: 4px; cursor: pointer; transition: background 0.3s; margin-top: 20px; } .calc-btn:hover { background: #2980b9; } .result-box { margin-top: 25px; padding: 20px; background: #fff; border-left: 5px solid #3498db; display: none; } .result-item { display: flex; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 10px; } .result-item:last-child { border-bottom: none; } .result-label { font-weight: 600; color: #555; } .result-value { font-weight: bold; color: #2c3e50; } .main-result { font-size: 1.2em; color: #27ae60; } .article-content h2 { color: #2c3e50; margin-top: 30px; border-bottom: 2px solid #eee; padding-bottom: 10px; } .article-content h3 { color: #34495e; margin-top: 20px; } .article-content p, .article-content li { margin-bottom: 15px; } .formula-box { background: #f0f8ff; padding: 15px; border-radius: 4px; font-family: monospace; text-align: center; font-size: 1.1em; margin: 20px 0; border: 1px solid #d1e8ff; }
True Positive Rate (Sensitivity) Calculator
The number of positive instances correctly predicted as positive.
The number of positive instances incorrectly predicted as negative (Type II errors).
True Positive Rate (Sensitivity):
TPR Percentage:
False Negative Rate (Miss Rate):
Total Actual Positives:
function calculateTPR() { // Get inputs by ID var tpInput = document.getElementById("truePositives"); var fnInput = document.getElementById("falseNegatives"); var tp = parseFloat(tpInput.value); var fn = parseFloat(fnInput.value); // Validation if (isNaN(tp) || isNaN(fn)) { alert("Please enter valid numbers for True Positives and False Negatives."); return; } if (tp < 0 || fn < 0) { alert("Values cannot be negative."); return; } var totalPositives = tp + fn; if (totalPositives === 0) { alert("Total actual positives (TP + FN) cannot be zero, as this results in division by zero."); return; } // Calculations var tpr = tp / totalPositives; var fnr = fn / totalPositives; // False Negative Rate // Formatting var tprFormatted = tpr.toFixed(4); var tprPercentFormatted = (tpr * 100).toFixed(2) + "%"; var fnrPercentFormatted = (fnr * 100).toFixed(2) + "%"; // Display Results document.getElementById("resTPR").innerHTML = tprFormatted; document.getElementById("resTPRPercent").innerHTML = tprPercentFormatted; document.getElementById("resFNR").innerHTML = fnrPercentFormatted; document.getElementById("resTotalPos").innerHTML = totalPositives; document.getElementById("resultDisplay").style.display = "block"; }

Understanding True Positive Rate (Sensitivity)

The True Positive Rate (TPR), also known as Sensitivity or Recall, is a crucial metric in statistics, machine learning, and medical diagnostics. It measures the proportion of actual positive cases that are correctly identified by a model or test.

In a binary classification problem (e.g., detecting spam emails or diagnosing a disease), it answers the question: "Of all the positive cases that exist, how many did we successfully find?"

The True Positive Rate Formula

To calculate the True Positive Rate, you need two values from the confusion matrix:

  • True Positives (TP): The number of cases correctly identified as positive.
  • False Negatives (FN): The number of actual positive cases that were incorrectly classified as negative (missed cases).
TPR = TP / (TP + FN)

The denominator (TP + FN) represents the total number of actual positive instances in the dataset.

Example Calculation

Imagine a medical test designed to detect a specific virus in 100 infected patients:

  • The test correctly identifies the virus in 90 patients (TP = 90).
  • The test fails to detect the virus in 10 patients, giving them a clean bill of health incorrectly (FN = 10).

Using the formula:

TPR = 90 / (90 + 10) = 90 / 100 = 0.90 or 90%

This means the test has a sensitivity of 90%.

Why is TPR Important?

High sensitivity is critical in scenarios where missing a positive case carries a high cost (also known as a Type II error).

  • Medical Diagnosis: You want to catch every instance of a disease. A False Negative could mean a sick patient goes untreated.
  • Security Screening: You want to detect every potential threat. Missing a threat (False Negative) is dangerous.

However, optimizing solely for TPR can sometimes lead to more False Positives (lowering Precision). A balanced evaluation often looks at both TPR and the False Positive Rate (FPR) using ROC curves.

Related Metrics

This calculator also displays the False Negative Rate (FNR), often called the "Miss Rate." It is the complement of TPR:

FNR = 1 – TPR

Leave a Comment