Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fd6e855
clarify docstring for existing helper function
ablaom Jan 20, 2026
ec697d7
add Functions.confusion_counts_at_thresholds
ablaom Jan 21, 2026
720c32f
refactor roc_curve(...) to use confusion_counts_at_thresholds(...)
ablaom Jan 21, 2026
18f3665
whitespace (correct formatting)
ablaom Jan 21, 2026
2489397
fix some incorrect loggging tests
ablaom Jan 21, 2026
44cf48e
doc string polish
ablaom Jan 22, 2026
f8e662b
add Functions.precision_recall_curve(...)
ablaom Jan 23, 2026
869db43
refactor some docstring generation, and fix threshold bins there
ablaom Feb 1, 2026
21e51c8
add precision_recall (the exported version); refactor runtests
ablaom Feb 1, 2026
a47453b
re-instate some forgotten tests after fixing them
ablaom Feb 1, 2026
884d00e
rm link to AreaUnderPrecisionRecallCurve, not yet added
ablaom Feb 2, 2026
182ad2b
add manual entry for PR curves
ablaom Feb 2, 2026
593fee2
add forgotten test file
ablaom Feb 2, 2026
a8376cd
rm redundant image (already in docs/src/assets)
ablaom Feb 2, 2026
5b12817
update roc manual entry
ablaom Feb 2, 2026
5426602
reverse precisions, recalls for consistency with roc return value
ablaom Feb 2, 2026
078a6da
include precision recall curves in make.jl and fix bad figure link
ablaom Feb 2, 2026
672b7d4
add cross-reference to confusion_counts_at_thresholds
ablaom Feb 2, 2026
5148f29
add examples from manual to roc/pc_curve docstrings
ablaom Feb 2, 2026
3a5fb81
fix one "positive_outcome"; should be "positive_class"
ablaom Feb 9, 2026
e7c66e5
improve doc-string to explain last and first points on the pr curve
ablaom Feb 10, 2026
eaa14bb
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
88b0025
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
895c560
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
05ba499
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
23426b6
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
6a4a9ac
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
26fd194
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
e9d65ba
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
61937d8
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
5dc8e98
Apply suggestion from @OkonSamuel
ablaom Mar 5, 2026
19b0524
revert overly enthusiastic delete to fix parsing error
ablaom Mar 5, 2026
b068053
in docstrings replace "plotting backend" -> "plotting library"
ablaom Mar 5, 2026
b56bbbf
fix two broken docstring cross-references
ablaom Mar 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
StatisticalMeasuresBase = "c062fc1d-0d66-479b-b6ac-8b44719de4cc"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -34,7 +35,7 @@ LossFunctions = "0.10, 0.11, 1"
MacroTools = "0.5"
OrderedCollections = "1"
PrecompileTools = "1.1"
ScientificTypes = "3"
REPL = "1"
ScientificTypesBase = "3"
StatisticalMeasuresBase = "0.1"
Statistics = "1"
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ makedocs(
"The Measures" => "auto_generated_list_of_measures.md",
"Confusion Matrices" => "confusion_matrices.md",
"Receiver Operator Characteristics" => "roc.md",
"Precision-Recall Curves" => "precision_recall.md",
"Tools" => "tools.md",
"Reference" => "reference.md",
],
Expand All @@ -41,4 +42,3 @@ deploydocs(
devbranch="dev",
push_preview=false,
)

Binary file added docs/src/assets/precision_recall_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions docs/src/precision_recall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Precision-Recall Curves

In binary classification problems, precision-recall curves (or PR curves) are a popular
alternative to [Receiver Operator Characteristics](@ref) when the target values are highly
imbalanced.

## Example

```@example 70
using StatisticalMeasures
using CategoricalArrays
using CategoricalDistributions

# ground truth:
y = categorical(["X", "O", "X", "X", "O", "X", "X", "O", "O", "X"], ordered=true)

# probabilistic predictions:
X_probs = [0.3, 0.2, 0.4, 0.9, 0.1, 0.4, 0.5, 0.2, 0.8, 0.7]
ŷ = UnivariateFinite(["O", "X"], X_probs, augment=true, pool=y)
ŷ[1]
```

```julia
using Plots
recalls, precisions, thresholds = precision_recall_curve(ŷ, y)
plt = plot(recalls, precisions, legend=false)
plot!(plt, xlab="recall", ylab="precision")

# proportion of observations that are positive:
p = precisions[end] # threshold=0
plot!([0, 1], [p, p], linewidth=2, linestyle=:dash, color=:black)
```

![](assets/precision_recall_curve.png)

## Reference

```@docs
precision_recall_curve
```
4 changes: 4 additions & 0 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Reference

```@index
Pages = ["reference.md",]
```

```@docs
StatisticalMeasuresBase.unwrap
StatisticalMeasuresBase.is_measure
Expand Down
4 changes: 2 additions & 2 deletions docs/src/roc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ŷ[1]

```julia
using Plots
curve = roc_curve(ŷ, y)
plt = plot(curve, legend=false)
false_positive_rates, true_positive_rates, thresholds = roc_curve(ŷ, y)
plt = plot(false_positive_rates, true_positive_rates; legend=false)
plot!(plt, xlab="false positive rate", ylab="true positive rate")
plot!([0, 1], [0, 1], linewidth=2, linestyle=:dash, color=:black)
```
Expand Down
Binary file removed docs/src/roc_curve.png
Binary file not shown.
21 changes: 4 additions & 17 deletions src/StatisticalMeasures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using LinearAlgebra
using StatsBase
import Distributions
using PrecompileTools
using REPL # needed for `Base.Docs.doc`

const SM = "StatisticalMeasures"
const CatArrOrSub{T, N} =
Expand All @@ -34,6 +35,7 @@ include("tools.jl")
include("functions.jl")
include("confusion_matrices.jl")
include("roc.jl")
include("precision_recall.jl")
include("docstrings.jl")
include("registry.jl")
include("continuous.jl")
Expand Down Expand Up @@ -71,22 +73,7 @@ export measures,
supports_missings_measure,
fussy_measure

export Functions, ConfusionMatrices, NoAvg, MacroAvg, MicroAvg, roc_curve

#tod look out for MLJBase.aggregate called on scalars, which is not supported here.
#todo in mljbase, single(measure, array1, array2)

#todo need a show(::Measure)
#todo `is_measure_type` in MLJBase is not provided here

#todo: following needs adding to section on continuous measures
# _scale(x, w::Arr, i) = x*w[i]
# _scale(x, ::Nothing, i::Any) = x

#todo: _skipinvalid from MLJBase/src/data/data.jl is needed for balanced accuracy, barring
# a refactor of that measure to use `skipinvalid` as provided in this package.

#todo: look for uses of aggregation of dictionaries in MLJBase, which is no longer
# supported, or add support.
export Functions, ConfusionMatrices, NoAvg, MacroAvg, MicroAvg
export roc_curve, precision_recall_curve

end
Loading
Loading