Can someone help me understand the "threshold" (i.e. the color gradient) in this precision recall curve (produced in R)?
https://i.stack.imgur.com/c64Tw.jpg
R code:
library(PRROC)
x <-rnorm(1000)
y <-rnorm(1000,-1)
pr <- pr.curve(x,y, curve=TRUE)
plot(pr)
Why does the threshold go from -3 to 3? Doesn't the threshold have to be between 0 and 1? Does anyone know how to fix this (produce a threshold between 0 and 1)?
Thanks!
source: https://cran.rstudio.com/web/packages/PRROC/PRROC.pdf
It is not really clear to me what you're trying to do; the figure you link to in the comments shows the precision/recall as a function of varying threshold parameters of a classifier, but you don't show code involving any classification problem.
Let's use the
iris
data set and construct a simple binary classification problem; to do so, we first remove all data forSpecies == "setosa"
.We then use a simple SVM with a Gaussian (radial) kernel for our classifier. In this case we have only one parameter
gamma
. We determine the precision/recall of our classifier for changing values ofgamma
and plot the resultsNote that the parameter(s) (and the values it/they take) depend(s) on your classifier; in this simple case you only have one single tunable parameter.
PS. I have used
ggplot
and othertidyverse
functions out of habit & convenience; you can do something similar in base R as well.