evalclass / precrec

An R library for accurate and fast calculations of Precision-Recall and ROC curves
https://evalclass.github.io/precrec
GNU General Public License v3.0
45 stars 5 forks source link

Having trouble understanding normalized rank calculation #12

Open rushabh31 opened 5 years ago

rushabh31 commented 5 years ago

I read all the instruction and vignettes available for precrec package, but I am having trouble understanding, how normalized rank is being calculated for basic mode. It would be really helpful, if you can include small introduction or explanation about it in the documentation or here.

I am looking forward for your reply.

Great work!!

Thank you.

takayasaito commented 5 years ago

Hi,

Normalized ranks are calculated as (ranks - 1)/(n - 1). Below is an example of R code to calculate normalized ranks in precrec.

> ranks <- c(3, 2, 1, 4)
> ranks
[1] 3 2 1 4
>
> n <- length(ranks)
> n
[1] 4
>
> (ranks - 1) / (n - 1)
[1] 0.6666667 0.3333333 0.0000000 1.0000000

Please notice the ranks in the example above are given higher ranks (as 1 is the best rank) for higher scores. It is different from the default R rank function.

> scores <- c(20, 75, 100, 1)
>
> # R's default rank function
> rank(scores)
[1] 2 3 4 1
>
> # precrec's rank function
> precrec::.rank_scores(scores)$ranks
[1] 3 2 1 4