So I need to plot a Sensitivity-Specificity curve. Since ROCs represent TPR (sensitivity) against FPR (or 1 - Specificity), can I just plot TPR against 1 - FPR as in the code below to obtain a Sens-Spec curve?

import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve


fpr, tpr, _ = roc_curve(y_test, y_score)
spec = 1 - fpr

#first plot (ROC)

#second plot (Sens-Spec?)

I plotted the results and compared it to the actual ROC, but I'm not sure if this is a correct way to do it or if I'm missing something. ROC and Sens-Spec

  • $\begingroup$ ROC = sensitivity vs. 1 - specificity. So sens vs spec is just flipped for one axis. Neither ROC nor sens vs spec are relevant because they make the error of transposed conditionals; each point is a conditional probability that conditions on what is unknown to compute the probability of what is already known. $\endgroup$ Commented Sep 1, 2022 at 15:45
  • $\begingroup$ @FrankHarrell thank you. That's what I was thinking but needed someone to confirm it. $\endgroup$ Commented Sep 1, 2022 at 17:02

1 Answer 1


Yes. The pROC package in R even writes the x-axis this way.

enter image description here

n <- 1000
p <- rbeta(N, 1, 1)
y <- rbinom(N, 1, p)
r <- pROC::roc(y, p)

The Frank Harrell in the comments has an interesting blog post about how sensitivity and specificity might be less useful than one might hope. Briefly, they condition on the unknown to predict the known.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.