How to Calculate the True Positive Rate

.tpr-calculator-container { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #e1e4e8; border-radius: 12px; background-color: #ffffff; box-shadow: 0 4px 15px rgba(0,0,0,0.05); color: #333; } .tpr-calculator-container h2 { color: #2c3e50; text-align: center; margin-bottom: 25px; font-size: 24px; } .input-group { margin-bottom: 20px; } .input-group label { display: block; font-weight: 600; margin-bottom: 8px; color: #4a5568; } .input-group input { width: 100%; padding: 12px; border: 2px solid #edf2f7; border-radius: 8px; font-size: 16px; box-sizing: border-box; transition: border-color 0.2s; } .input-group input:focus { outline: none; border-color: #4299e1; } .calculate-btn { width: 100%; padding: 15px; background-color: #4299e1; color: white; border: none; border-radius: 8px; font-size: 18px; font-weight: 700; cursor: pointer; transition: background-color 0.2s; } .calculate-btn:hover { background-color: #3182ce; } .result-box { margin-top: 25px; padding: 20px; border-radius: 8px; background-color: #f7fafc; display: none; } .result-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #e2e8f0; } .result-row:last-child { border-bottom: none; } .result-label { font-weight: 500; color: #4a5568; } .result-value { font-weight: 700; color: #2b6cb0; } .article-section { margin-top: 40px; line-height: 1.6; color: #4a5568; } .article-section h3 { color: #2c3e50; margin-top: 25px; } .formula-box { background-color: #edf2f7; padding: 15px; border-radius: 8px; font-family: "Courier New", Courier, monospace; text-align: center; margin: 20px 0; font-weight: bold; } .example-card { background-color: #fffaf0; border-left: 4px solid #ed8936; padding: 15px; margin: 20px 0; }

True Positive Rate (Sensitivity) Calculator

True Positive Rate (TPR): 0.000
Sensitivity (Percentage): 0%
False Negative Rate (FNR): 0.000

What is the True Positive Rate?

The True Positive Rate (TPR), also known as Sensitivity or Recall, is a critical metric in statistics, machine learning, and medical testing. It measures the proportion of actual positive cases that were correctly identified by a test or model. In simpler terms, it answers the question: "Of all the people who actually have the condition, how many did the test correctly catch?"

The Mathematical Formula

Calculating the TPR requires data from a confusion matrix. You need to know the number of True Positives (cases correctly identified as positive) and False Negatives (actual positive cases that the test missed).

TPR = True Positives (TP) / [True Positives (TP) + False Negatives (FN)]

How to Interpret Results

  • TPR = 1.0 (100%): The test is perfect at identifying positive cases. There are no False Negatives.
  • High TPR: The test is highly sensitive. It is excellent for screening because it rarely misses a positive case.
  • Low TPR: The test is "leaky." Many positive cases are going undetected (Type II Error).

Realistic Example: Cancer Screening

Imagine a medical study for a new diagnostic test involving 100 patients who actually have a specific disease:

  • The test correctly identifies 92 patients (True Positives = 92).
  • The test misses 8 patients, incorrectly telling them they are healthy (False Negatives = 8).

Calculation: 92 / (92 + 8) = 0.92

The True Positive Rate (Sensitivity) is 92%.

Why TPR Matters in Machine Learning

In binary classification, looking at accuracy alone can be misleading, especially with imbalanced datasets. If you are building a fraud detection system where only 1% of transactions are fraudulent, a model that labels everything as "not fraud" will be 99% accurate but have a 0% True Positive Rate. In high-stakes environments like medicine or security, maximizing TPR is often more important than maximizing overall accuracy.

function calculateTPR() { var tpInput = document.getElementById('true_positives'); var fnInput = document.getElementById('false_negatives'); var resultBox = document.getElementById('tpr_result_box'); var tp = parseFloat(tpInput.value); var fn = parseFloat(fnInput.value); // Validation if (isNaN(tp) || isNaN(fn)) { alert("Please enter valid numbers for both fields."); return; } if (tp < 0 || fn < 0) { alert("Inputs cannot be negative."); return; } var totalActualPositives = tp + fn; if (totalActualPositives === 0) { alert("The sum of TP and FN must be greater than zero to perform this calculation."); return; } // Calculation Logic var tpr = tp / totalActualPositives; var tprPercentage = tpr * 100; var fnr = fn / totalActualPositives; // Displaying results document.getElementById('tpr_value').innerText = tpr.toFixed(4); document.getElementById('tpr_percentage').innerText = tprPercentage.toFixed(2) + "%"; document.getElementById('fnr_value').innerText = fnr.toFixed(4); resultBox.style.display = 'block'; }

Leave a Comment