To determine the level of error in the precision and recall values for your ternary classification (classes A, B, and C) with a total of (X) samples, we need to compute the 95% confidence intervals for each precision ((p_A), (p_B), (p_C)) and recall ((r_A), (r_B), (r_C)). The "level of error" refers to the margin of error within these confidence intervals, which quantifies the uncertainty in the estimated proportions.
Key Concepts
- Precision and recall are proportions derived from classification performance metrics:
- Precision for a class (e.g., (p_A)) is the ratio of true positives (TP) to the total predicted positives (PP) for that class: (p_A = \text{TP}_A / \text{PP}_A).
- Recall for a class (e.g., (r_A)) is the ratio of true positives (TP) to the total actual positives (AP) for that class: (r_A = \text{TP}_A / \text{AP}_A).
- The confidence interval for a proportion depends on the sample size (denominator) used in the calculation. For precision, the sample size is the number of predicted positives ((\text{PP}_A), (\text{PP}_B), (\text{PP}_C)). For recall, it is the number of actual positives ((\text{AP}_A), (\text{AP}_B), (\text{AP}_C)).
- In a single-label ternary classification (where each sample belongs to exactly one class), the sum of actual positives should equal the total samples: (\text{AP}_A + \text{AP}_B + \text{AP}_C = X). Similarly, the sum of predicted positives should equal (X): (\text{PP}_A + \text{PP}_B + \text{PP}_C = X).
- The 95% confidence interval for a proportion can be approximated using the normal distribution (valid for large sample sizes). The margin of error is given by (1.96 \times \text{standard error (SE)}), where SE = (\sqrt{p(1-p)/n}), and (n) is the sample size for the proportion.
Confidence Interval Formulas
For each class, the 95% confidence interval and margin of error are as follows:
-
For precision ((p_A), (p_B), (p_C)):
- Sample size: Number of predicted positives ((\text{PP}_A), (\text{PP}_B), (\text{PP}_C)).
- Margin of error: (1.96 \times \sqrt{\frac{p \times (1 - p)}{\text{PP}}})
- 95% Confidence Interval: ([p - \text{margin of error}, p + \text{margin of error}])
Specifically:
- For class A: Margin of error = (1.96 \times \sqrt{\frac{p_A \times (1 - p_A)}{\text{PP}_A}}), CI = ([p_A - \text{margin of error}, p_A + \text{margin of error}])
- For class B: Margin of error = (1.96 \times \sqrt{\frac{p_B \times (1 - p_B)}{\text{PP}_B}}), CI = ([p_B - \text{margin of error}, p_B + \text{margin of error}])
- For class C: Margin of error = (1.96 \times \sqrt{\frac{p_C \times (1 - p_C)}{\text{PP}_C}}), CI = ([p_C - \text{margin of error}, p_C + \text{margin of error}])
-
For recall ((r_A), (r_B), (r_C)):
- Sample size: Number of actual positives ((\text{AP}_A), (\text{AP}_B), (\text{AP}_C)).
- Margin of error: (1.96 \times \sqrt{\frac{r \times (1 - r)}{\text{AP}}})
- 95% Confidence Interval: ([r - \text{margin of error}, r + \text{margin of error}])
Specifically:
- For class A: Margin of error = (1.96 \times \sqrt{\frac{r_A \times (1 - r_A)}{\text{AP}_A}}), CI = ([r_A - \text{margin of error}, r_A + \text{margin of error}])
- For class B: Margin of error = (1.96 \times \sqrt{\frac{r_B \times (1 - r_B)}{\text{AP}_B}}), CI = ([r_B - \text{margin of error}, r_B + \text{margin of error}])
- For class C: Margin of error = (1.96 \times \sqrt{\frac{r_C \times (1 - r_C)}{\text{AP}_C}}), CI = ([r_C - \text{margin of error}, r_C + \text{margin of error}])
Important Notes
- Required Inputs: To compute the exact confidence intervals and margins of error, you need the per-class sample sizes ((\text{PP}_A), (\text{PP}_B), (\text{PP}_C) for precision and (\text{AP}_A), (\text{AP}_B), (\text{AP}_C) for recall). These can be obtained from your confusion matrix or performance metrics:
- (\text{AP}_A), (\text{AP}_B), (\text{AP}_C) are the true class counts (e.g., number of samples actually in class A).
- (\text{PP}_A), (\text{PP}_B), (\text{PP}_C) are the predicted class counts (e.g., number of samples predicted as class A).
- Assumptions and Limitations:
- The normal approximation is generally reliable when the sample sizes ((\text{PP}) or (\text{AP})) are large (e.g., >30 and the proportion is not too close to 0 or 1). If sample sizes are small, consider using a more accurate method like the Wilson score interval.
- The total samples (X) alone are not sufficient to compute the intervals, as the denominators ((\text{PP}) and (\text{AP})) vary per class.
- If your classification is multi-label (where a sample can belong to multiple classes), the sums of (\text{AP}_A + \text{AP}_B + \text{AP}_C) and (\text{PP}_A + \text{PP}_B + \text{PP}_C) may exceed (X), but the same formulas apply.
- Example Calculation: Suppose for class A, (p_A = 0.85), (\text{PP}_A = 100), (r_A = 0.90), and (\text{AP}_A = 80):
- Precision margin of error: (1.96 \times \sqrt{\frac{0.85 \times (1 - 0.85)}{100}} \approx 1.96 \times \sqrt{\frac{0.85 \times 0.15}{100}} \approx 1.96 \times 0.0367 \approx 0.072), so CI ≈ [0.778, 0.922].
- Recall margin of error: (1.96 \times \sqrt{\frac{0.90 \times (1 - 0.90)}{80}} \approx 1.96 \times \sqrt{\frac{0.90 \times 0.10}{80}} \approx 1.96 \times 0.0333 \approx 0.065), so CI ≈ [0.835, 0.965].
Next Steps
- If you have the values for (\text{PP}_A), (\text{PP}_B), (\text{PP}_C), (\text{AP}_A), (\text{AP}_B), and (\text{AP}_C), you can plug them into the formulas above to compute the specific margins of error and confidence intervals.
- If you provide these additional details or the confusion matrix for your data, I can assist with the calculations or refine this response.
This approach ensures the confidence intervals accurately reflect the uncertainty in your precision and recall estimates based on your data.