Skip to contents

Precision and recall at each distinct score; AP = sum (R_k - R_{k-1}) P_k, with no interpolation. best_f1 picks the first maximum.

Usage

morie_geron_precision_recall_curve(y_true, y_scores)

Arguments

y_true

Binary 0/1 labels.

y_scores

Decision scores.

Value

List with precision, recall, thresholds, f1, average_precision, best_f1, best_threshold.

Examples

set.seed(1)
y <- rbinom(30, 1, 0.5)
s <- y + rnorm(30, 0, 0.7)
morie_geron_precision_recall_curve(y, s)
#> $precision
#>  [1] 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
#>  [8] 1.0000000 1.0000000 0.9000000 0.9090909 0.8333333 0.8461538 0.7857143
#> [15] 0.7333333 0.6875000 0.6470588 0.6666667 0.6315789 0.6500000 0.6190476
#> [22] 0.5909091 0.5652174 0.5416667 0.5200000 0.5000000 0.4814815 0.4642857
#> [29] 0.4827586 0.4666667
#> 
#> $recall
#>  [1] 0.07142857 0.14285714 0.21428571 0.28571429 0.35714286 0.42857143
#>  [7] 0.50000000 0.57142857 0.64285714 0.64285714 0.71428571 0.71428571
#> [13] 0.78571429 0.78571429 0.78571429 0.78571429 0.78571429 0.85714286
#> [19] 0.85714286 0.92857143 0.92857143 0.92857143 0.92857143 0.92857143
#> [25] 0.92857143 0.92857143 0.92857143 0.92857143 1.00000000 1.00000000
#> 
#> $thresholds
#>  [1]  1.66068535  1.64328416  1.57485484  1.54749541  1.38966424  1.29255909
#>  [7]  1.27137013  1.05219549  0.95848062  0.95107569  0.92804859  0.77001776
#> [13]  0.70950381  0.53422302  0.48787436  0.43387802  0.41573092  0.03605831
#> [19] -0.01133318 -0.02952667 -0.03145353 -0.03766353 -0.03929012 -0.10905685
#> [25] -0.11516652 -0.17735318 -0.27600297 -0.33470504 -0.39254619 -0.48212899
#> 
#> $f1
#>  [1] 0.1333333 0.2500000 0.3529412 0.4444444 0.5263158 0.6000000 0.6666667
#>  [8] 0.7272727 0.7826087 0.7500000 0.8000000 0.7692308 0.8148148 0.7857143
#> [15] 0.7586207 0.7333333 0.7096774 0.7500000 0.7272727 0.7647059 0.7428571
#> [22] 0.7222222 0.7027027 0.6842105 0.6666667 0.6500000 0.6341463 0.6190476
#> [29] 0.6511628 0.6363636
#> 
#> $average_precision
#> [1] 0.8967621
#> 
#> $best_f1
#> [1] 0.8148148
#> 
#> $best_threshold
#> [1] 0.7095038
#> 
#> $estimate
#> [1] 0.8967621
#> 
#> $n
#> [1] 30
#>