-
Notifications
You must be signed in to change notification settings - Fork 7
add continuous boyce index #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9b55804
first draft
tiemvanderdeure f7560b7
move warn_unordered
tiemvanderdeure f2beeed
add some tests
tiemvanderdeure 381a707
refactor, move main algo to functions.jl
tiemvanderdeure 479eb8c
refer to functions in docstring
tiemvanderdeure fe58b7b
fix warn_unordered
tiemvanderdeure 1aff4f1
fix another warn_unordered
tiemvanderdeure 987bf06
always call warn_unordered in roc (the if-else logic is now in there)
tiemvanderdeure f735f5d
fix non exported functions in test
tiemvanderdeure 30bccf9
only index binstarts if necessary
tiemvanderdeure 2c9851b
test logs
tiemvanderdeure 9a6b932
Merge branch 'dev' into cbi
tiemvanderdeure b47634d
fix info message
tiemvanderdeure 5723e5e
one more test for dropping bins
tiemvanderdeure 46fd4bc
improve docstring
tiemvanderdeure 7c4a9b9
levels not classes
tiemvanderdeure 36ae7b6
fix constants
tiemvanderdeure 3785741
loosen dispatch
tiemvanderdeure c17f0b7
add verbosity
tiemvanderdeure 58fdd66
change some defaults that
tiemvanderdeure d3122db
fix tests
tiemvanderdeure File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -544,3 +544,85 @@ $DOC_DISTRIBUTIONS | |||||
| SphericalScore | ||||||
| "$SphericalScoreDoc" | ||||||
| const spherical_score = SphericalScore() | ||||||
|
|
||||||
|
|
||||||
| # --------------------------------------------------------------------- | ||||||
| # Continuous Boyce Index | ||||||
| struct _ContinuousBoyceIndex | ||||||
| nbins::Integer | ||||||
| bin_overlap::AbstractFloat | ||||||
| min::Union{AbstractFloat, Nothing} | ||||||
| max::Union{AbstractFloat, Nothing} | ||||||
| cor::Function | ||||||
| function _ContinuousBoyceIndex(; nbins = 101, bin_overlap = 0.1, min = nothing, max = nothing, cor = StatsBase.corspearman) | ||||||
| new(nbins, bin_overlap, min, max, cor) | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| ContinuousBoyceIndex(; kw...) = _ContinuousBoyceIndex(; kw...) |> robust_measure |> fussy_measure | ||||||
|
|
||||||
| function (m::_ContinuousBoyceIndex)(ŷ::UnivariateFiniteArray, y::NonMissingCatArrOrSub; warn=true) | ||||||
| warn && warn_unordered(levels(y)) | ||||||
| positive_class = levels(first(ŷ))|> last | ||||||
| scores = pdf.(ŷ, positive_class) | ||||||
| max = isnothing(m.max) ? maximum(scores) : m.max | ||||||
| min = isnothing(m.min) ? minimum(scores) : m.min | ||||||
| binwidth = m.bin_overlap * (max - min) | ||||||
|
|
||||||
| return Functions.cbi(scores, y, positive_class; nbins = m.nbins, binwidth, max, min, cor = m.cor) | ||||||
| end | ||||||
|
|
||||||
| const ContinuousBoyceIndexType = API.FussyMeasure{<:API.RobustMeasure{<:_ContinuousBoyceIndex}} | ||||||
|
|
||||||
| @fix_show ContinuousBoyceIndex::ContinuousBoyceIndexType | ||||||
|
|
||||||
| StatisticalMeasures.@trait( | ||||||
| _ContinuousBoyceIndex, | ||||||
| consumes_multiple_observations=true, | ||||||
| observation_scitype = Finite{2}, | ||||||
| kind_of_proxy=StatisticalMeasures.LearnAPI.Distribution(), | ||||||
| orientation=Score(), | ||||||
| external_aggregation_mode=Mean(), | ||||||
| human_name = "continuous boyce index", | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Suggested change
|
||||||
| ) | ||||||
|
|
||||||
| register(ContinuousBoyceIndex, "continuous_boyce_index", "cbi") | ||||||
|
|
||||||
| const ContinuousBoyceIndexDoc = docstring( | ||||||
| "ContinuousBoyceIndex(; nbins=101, bin_overlap=0.1, min=nothing, max=nothing, cor=StatsBase.corspearman)", | ||||||
| body= | ||||||
| """ | ||||||
| The Continuous Boyce Index is a measure for evaluating the performance of probabilistic predictions for binary classification, | ||||||
| especially for presence-background data in ecological modeling. | ||||||
| It compares the predicted probability scores for the positive class across bins, giving higher scores if the ratio of positive | ||||||
| and negative samples in each bin is strongly correlated to the value at that bin. | ||||||
|
|
||||||
| ## Keywords | ||||||
|
|
||||||
| - `nbins`: Number of bins to use for score partitioning. | ||||||
| - `bin_overlap`: Relative overlap between bins. The actual bin width is `bin_overlap * (max - min)`. | ||||||
| - `min`, `max`: Optional minimum and maximum score values for binning. Default to the | ||||||
| maximum and minimum values of the scores. | ||||||
| - `cor`: Correlation function (defaults to StatsBase.corspearman, i.e. Spearman correlation). | ||||||
|
|
||||||
| ## Arguments | ||||||
|
|
||||||
| The predictions `ŷ` should be a vector of `UnivariateFinite` distributions from CategoricalDistributions.jl, and `y` a vector of ground truth labels. | ||||||
|
|
||||||
| Returns the correlation between the ratio of positive to negative samples in each bin and the bin centers. | ||||||
|
|
||||||
| Core implementation: [`Functions.cbi`](@ref). | ||||||
|
|
||||||
| Reference: | ||||||
| Alexandre H. Hirzel, Gwenaëlle Le Lay, Véronique Helfer, Christophe Randin, Antoine Guisan, | ||||||
| Evaluating the ability of habitat suitability models to predict species presences, | ||||||
| Ecological Modelling, | ||||||
| Volume 199, Issue 2, 2006 | ||||||
| """, | ||||||
| scitype="", | ||||||
| ) | ||||||
|
|
||||||
| "$ContinuousBoyceIndexDoc" | ||||||
| ContinuousBoyceIndex | ||||||
| "$ContinuousBoyceIndexDoc" | ||||||
| const cbi(x, y) = ContinuousBoyceIndex()(x, y) | ||||||
|
tiemvanderdeure marked this conversation as resolved.
Outdated
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation for
yhatis too strict. Either remove it altogether, or you could do::AbstractArray{<:UnivariateFinite}. For consider