Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous precision recall curve and PR-AUC for null classifier #526

Open
longjp opened this issue Nov 12, 2024 · 0 comments
Open

Erroneous precision recall curve and PR-AUC for null classifier #526

longjp opened this issue Nov 12, 2024 · 0 comments

Comments

@longjp
Copy link

longjp commented Nov 12, 2024

If a classifier predicts all same value, then precision-recall curve should be horizontal line at y= # positivies / # observations. PR-AUC should be = # positivies / # observations (integrating constant from 0 to 1). However this is not what the pr_curve or pr_auc function returns.

library(yardstick)
library(ggplot2)
library(tidyr)

head(two_class_example)


## real pr curve
pr <- pr_curve(two_class_example, truth, Class1)
pr %>%
  ggplot(aes(x = recall, y = precision)) +
  geom_path() +
  coord_equal() +
  theme_bw()
pr_auc(two_class_example, truth, Class1)




## pr curve with random predictions, looks fine
two_class_example$noisy_pred <- rnorm(nrow(two_class_example))
pr <- pr_curve(two_class_example, truth, noisy_pred)
pr %>%
  ggplot(aes(x = recall, y = precision)) +
  geom_path() +
  coord_equal() +
  theme_bw() +
  ylim(c(0,1))
pr_auc(two_class_example, truth, noisy_pred)
## result is near 0.5 because class1 and class2 roughly balanced


## pr curve with always 0 predictions, WRONG result
two_class_example$fake_pred <- 0
pr <- pr_curve(two_class_example, truth, fake_pred)
pr %>%
  ggplot(aes(x = recall, y = precision)) +
  geom_path() +
  coord_equal() +
  theme_bw() +
  ylim(c(0,1))
pr_auc(two_class_example, truth, fake_pred)
## result is 0.758, way too high

erroneous-pr-curve.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant