@@ -544,3 +544,89 @@ $DOC_DISTRIBUTIONS
544544SphericalScore
545545" $SphericalScoreDoc "
546546const spherical_score = SphericalScore()
547+
548+
549+ # ---------------------------------------------------------------------
550+ # Continuous Boyce Index
551+ struct _ContinuousBoyceIndex
552+ verbosity:: Int
553+ nbins:: Integer
554+ binwidth:: Float64
555+ min:: Float64
556+ max:: Float64
557+ cor:: Function
558+ function _ContinuousBoyceIndex(;
559+ verbosity = 1 , nbins = 101 , binwidth = 0.1 ,
560+ min = 0 , max = 1 , cor = StatsBase. corspearman
561+ )
562+ new(verbosity, nbins, binwidth, min, max, cor)
563+ end
564+ end
565+
566+ ContinuousBoyceIndex(; kw... ) = _ContinuousBoyceIndex(; kw... ) |> robust_measure |> fussy_measure
567+
568+ function (m:: _ContinuousBoyceIndex )(ŷ:: AbstractArray{<:UnivariateFinite} , y:: NonMissingCatArrOrSub )
569+ m. verbosity > 0 && warn_unordered(levels(y))
570+ positive_class = levels(first(ŷ))|> last
571+ scores = pdf.(ŷ, positive_class)
572+
573+ return Functions. cbi(scores, y, positive_class;
574+ verbosity = m. verbosity, nbins = m. nbins, binwidth = m. binwidth, max = m. max, min = m. min, cor = m. cor)
575+ end
576+
577+ const ContinuousBoyceIndexType = API. FussyMeasure{<: API.RobustMeasure{<:_ContinuousBoyceIndex} }
578+
579+ @fix_show ContinuousBoyceIndex:: ContinuousBoyceIndexType
580+
581+ StatisticalMeasures. @trait(
582+ _ContinuousBoyceIndex,
583+ consumes_multiple_observations= true ,
584+ observation_scitype = Finite{2 },
585+ kind_of_proxy= StatisticalMeasures. LearnAPI. Distribution(),
586+ orientation= Score(),
587+ external_aggregation_mode= Mean(),
588+ human_name = " continuous Boyce index" ,
589+ )
590+
591+ register(ContinuousBoyceIndex, " continuous_boyce_index" , " cbi" )
592+
593+ const ContinuousBoyceIndexDoc = docstring(
594+ " ContinuousBoyceIndex(; verbosity=1, nbins=101, bin_overlap=0.1, min=nothing, max=nothing, cor=StatsBase.corspearman)" ,
595+ body=
596+ """
597+ The Continuous Boyce Index is a measure for evaluating the performance of probabilistic predictions for binary classification,
598+ especially for presence-background data in ecological modeling.
599+ It compares the predicted probability scores for the positive class across bins, giving higher scores if the ratio of positive
600+ and negative samples in each bin is strongly correlated to the value at that bin.
601+
602+ ## Keywords
603+ - `verbosity`: Verbosity level.
604+ - `nbins`: Number of bins to use for score partitioning.
605+ - `binwidth`: The width of each bin, which defaults to 0.1.
606+ - `min`, `max`: Optional minimum and maximum score values for binning. Default to the 0 and 1, respectively.
607+ - `cor`: Correlation function (defaults to StatsBase.corspearman, i.e. Spearman correlation).
608+
609+ ## Arguments
610+
611+ The predictions `ŷ` should be a vector of `UnivariateFinite` distributions from CategoricalDistributions.jl,
612+ and `y` a CategoricalVector of ground truth labels.
613+
614+ Returns the correlation between the ratio of positive to negative samples in each bin and the bin centers.
615+
616+ Core implementation: [`Functions.cbi`](@ref).
617+
618+ Reference:
619+ Alexandre H. Hirzel, Gwenaëlle Le Lay, Véronique Helfer, Christophe Randin, Antoine Guisan,
620+ Evaluating the ability of habitat suitability models to predict species presences,
621+ Ecological Modelling,
622+ Volume 199, Issue 2, 2006
623+ """ ,
624+ scitype= " " ,
625+ )
626+
627+ " $ContinuousBoyceIndexDoc "
628+ ContinuousBoyceIndex
629+ " $ContinuousBoyceIndexDoc "
630+ const cbi = ContinuousBoyceIndex()
631+ " $ContinuousBoyceIndexDoc "
632+ const continuous_boyce_index = ContinuousBoyceIndex()
0 commit comments