Specificity, or the true negative rate, measures the proportion of actual negative instances that a classifier correctly identifies as negative. Compute it as TN / (TN + FP), then multiply by 100 for a percentage. It evaluates how well a binary model avoids incorrectly labeling negatives as positives. section 5.2.4
Table 5.1 Confusion matrix for raisin classification. A confusion matrix stores classification metrics from a regression with actual and predicted binary outcomes.
|
Predicted
|
|||
|---|---|---|---|
|
Kecimen (0)
|
Besni (1)
|
||
|
Actual
|
Kecimen (0)
|
tn
|
fp
|
|
Besni (1)
|
fn
|
tp
|
|
Read specificity from the negative-class row of the confusion matrix: true negatives are correctly predicted negatives, while false positives are actual negatives predicted as positive. section 5.2.4
Calculate and interpret specificity in Python:
- Use the confusion-matrix counts directly: specificity = (tn / (tn + fp)) * 100. section 5.2.4
- Use sklearn.metrics.recall_score with pos_label=0 to calculate recall for the negative class: recall_score(Class, prediction, pos_label=0). section 5.2.4
- Compare specificity with sensitivity and the false positive rate rather than treating it as a complete evaluation; false positive rate is its inverse. section 5.2.4 section 5.3
Raisin classification
A logistic regression correctly predicts 397 negative cases and incorrectly predicts 53 negatives as positive. Its specificity is 397 / (397 + 53) × 100 = 88.22%. The corresponding false positive rate is 11.78%, indicating that the model performs similarly across its two classes when considered alongside its 85.33% sensitivity. section 5.2.4





