How we calculate Precision-Recall Curve?
Obviously, you can't plot a curve from a single pair of values, so you have to find a parameter to vary that changes your problem in a way that makes sense to what you're trying to do.

For example, suppose your binary classification problem has a choosable threshold.  If you vary the threshold up and down, then it will change the precision and recall.

Then you might get a plot like the one below.  R code below that generated it.





R Code

#26568

Ndata &lt;- 1000

c1 &lt;- runif(Ndata,1.5,3)
c2 &lt;- runif(Ndata,1,2.5)

data &lt;- c(c1, c2)

thresholds &lt;- seq(1,2.99,0.01)

precision &lt;- thresholds*0
recall &lt;- thresholds*0

for (k in 1:length(thresholds))
{
  threshold &lt;- thresholds[k]
  cl &lt;- data*0
  tp &lt;- 0
  tn &lt;- 0
  fp &lt;- 0
  fn &lt;- 0

  for (i in 1:length(data))
  {
    if ( (data[i] &gt; threshold) &amp;&amp; (i &lt;= Ndata))
    {
      tp &lt;- tp + 1  
    }
    if ( (data[i] &gt; threshold) &amp;&amp; (i &gt; Ndata))
    {
      fp &lt;- fp + 1  
    }
    if ( (data[i] &lt;= threshold) &amp;&amp; (i &lt;= Ndata))
    {
      fn &lt;- fn + 1  
    }
    if ( (data[i] &lt;= threshold) &amp;&amp; (i &gt; Ndata))
    {
      tn &lt;- tn + 1  
    }
  }

  precision[k] &lt;- tp / (tp + fp)
  recall[k] &lt;- tp / (tp  + fn)
}

plot(precision,recall)