ROC.jl

Receiver Operating Characteristic (ROC) Curve for Julia Language
Popularity
8 Stars
Updated Last
8 Months Ago
Started In
April 2014

ROC

Roc destroying Sindbad's ship from The Book of Knowledge, The Grolier Society, 1911

Linux, OSX: Build Status
Windows: Build status
Code Coverage: Coverage Status codecov.io

An implementation of ROC (Receiver Operating Characteristic) curves for Julia.

Installation

] add https://github.com/diegozea/ROC.jl

Use

roc(scores::AbstractVector{T}, labels::AbstractVector{U}, truelabel::L; distances::Bool=false)

Here T is R or Union{R,Missing} for some type R<:Real and U is L or Union{L,Missing} for some type L<:Any. The labels vector must take exactly two non-missing values.

distances defines whether the scores values are distance-scored, i.e. a higher score value means a worse match. The default is false indicating the more typical opposite case where a higher score value means a better match

roc(scores::AbstractVector{R}, labels::BitVector{Bool}; distances::Bool=false)

Alternative method for optimal performance (no missing values allowed).

The methods above return a ROCData object, whose fields FPR and TPR are the vectors of true and false positive rates, respectively.

AUC(curve::ROCData)

Area under the curve.

PPV(curve::ROCData)

Positive predictive value.

Example

Generate synthetic data:

julia> function noisy(label; λ=0.0)
           if label
               return 1 - λ*rand()
           else
               return λ*rand()
           end
       end

julia> labels = rand(Bool, 200);

julia> scores(λ) = map(labels) do label
           noisy(label, λ=λ)
       end

Compare area under ROC curves:

julia> using ROC

julia> roc_good = roc(scores(0.6), labels, true);
julia> roc_bad = roc(scores(1.0), labels, true);

julia> area_good = AUC(roc_good)
0.9436237564063913

julia> area_bad =  AUC(roc_bad)
0.5014571399859311

Use Plots.jl to plot the receiver operator characteristics:

julia> using Plots

julia> plot(roc_good, label="good");
julia> plot!(roc_bad, label="bad")

This generates the plot appearing at the top of the page.