True Positive Rate Calculator
Result:
True Positive Rate (Sensitivity/Recall) will be displayed here.
What is the True Positive Rate?
The True Positive Rate, also known as Sensitivity or Recall, is a crucial metric in evaluating the performance of a classification model. It measures the proportion of actual positive cases that were correctly identified by the model. In simpler terms, it tells you how well your model can detect all the positive instances.
A high True Positive Rate indicates that the model is good at identifying positive cases and has a low rate of false negatives. Conversely, a low True Positive Rate suggests that the model is missing many actual positive cases, leading to a high number of false negatives.
The formula for calculating the True Positive Rate is:
True Positive Rate = True Positives (TP) / (True Positives (TP) + False Negatives (FN))
Where:
- True Positives (TP): The number of instances that were correctly predicted as positive.
- False Negatives (FN): The number of instances that were actually positive but were incorrectly predicted as negative.
The True Positive Rate is expressed as a value between 0 and 1, or as a percentage between 0% and 100%.
.calculator-container {
font-family: sans-serif;
margin: 20px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-inputs, .calculator-result, .calculator-explanation {
margin-bottom: 20px;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.input-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
#result {
padding: 15px;
border: 1px solid #d4edda;
background-color: #d4edda;
color: #155724;
border-radius: 4px;
}
.calculator-explanation h3 {
color: #333;
}
.calculator-explanation p, .calculator-explanation ul {
line-height: 1.6;
}
.calculator-explanation code {
background-color: #e9ecef;
padding: 2px 5px;
border-radius: 3px;
}
function calculateTruePositiveRate() {
var tpInput = document.getElementById("truePositives");
var fnInput = document.getElementById("falseNegatives");
var resultDiv = document.getElementById("result");
var truePositives = parseFloat(tpInput.value);
var falseNegatives = parseFloat(fnInput.value);
if (isNaN(truePositives) || isNaN(falseNegatives) || truePositives < 0 || falseNegatives < 0) {
resultDiv.innerHTML = "Please enter valid non-negative numbers for True Positives and False Negatives.";
return;
}
var totalActualPositives = truePositives + falseNegatives;
if (totalActualPositives === 0) {
resultDiv.innerHTML = "True Positive Rate cannot be calculated as there are no actual positive instances (TP + FN = 0).";
} else {
var tpr = (truePositives / totalActualPositives);
resultDiv.innerHTML =
"
True Positive Rate (TPR): " + tpr.toFixed(4) + "" +
"
As a percentage: " + (tpr * 100).toFixed(2) + "%" +
"(TP: " + truePositives + ", FN: " + falseNegatives + ", Total Actual Positives: " + totalActualPositives + ")";
}
}