liveBook · Manning

Specificity

As explained in Statistics Every Programmer Needs

Specificity is the proportion of actual negative instances that a classifier correctly identifies as negative.

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

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the formula, derives it from confusion-matrix counts, implements it manually and with scikit-learn, and compares it with related rates.
Examples
Uses raisin-classification counts of 397 true negatives and 53 false positives to obtain 88.22% specificity.
What it assumes
Assumes binary actual and predicted outcomes plus familiarity with true negatives and false positives; introduces negative-class recall explicitly.
What you can do after
Apply it via Python or scikit-learn to quantify a classifier’s negative-class performance and interpret false-positive errors.
How it connects
Connects specificity to confusion matrices, sensitivity, false positive rate, logistic regression, and ROC analysis.

Also explained in

Compare how 6 books explain specificity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.