Liking cljdoc? Tell your friends :D

fastmath.stats.binary

Binary measures functions

Binary measures functions
raw docstring

->f-betaclj

(->f-beta beta)

f-beta score creator, returns f-beta measure function for given beta.

beta only appears squared in the formula, so its sign doesn't matter -- beta and -beta produce the same measure function. See also f1-score (the beta=1 case) and ->f-inv-beta (the reciprocal).

f-beta score creator, returns f-beta measure function for given `beta`.

`beta` only appears squared in the formula, so its sign doesn't matter --
`beta` and `-beta` produce the same measure function. See also [[f1-score]]
(the `beta=1` case) and [[->f-inv-beta]] (the reciprocal).
raw docstring

->f-inv-betaclj

(->f-inv-beta beta)

Inversed f-beta score creator, returns inversed f-beta measure function for given beta

Inversed f-beta score creator, returns inversed f-beta measure function for given `beta`
raw docstring

accuracyclj

(accuracy {:keys [tp fp fn tn]})
(accuracy tp fp fn tn)

Accuracy

Accuracy
raw docstring

adj-f-scoreclj

(adj-f-score {:keys [tp fp fn tn]})
(adj-f-score tp fp fn tn)

Adjusted f-score, agf

Adjusted f-score, agf
raw docstring

agfclj

(agf {:keys [tp fp fn tn]})
(agf tp fp fn tn)

Adjusted f-score, agf

Adjusted f-score, agf
raw docstring

baclj

(ba {:keys [tp fp fn tn]})
(ba tp fp fn tn)

Balanced accuracy

Balanced accuracy
raw docstring

binary-confusionclj

(binary-confusion t p)

Assign category to a pair of true and predicted values.

Returned category is one of the following:

  • :tp - true positive
  • :fn - false negative
  • :fp - false positive
  • :tn - true negative
Assign category to a pair of true and predicted values.

Returned category is one of the following:

* `:tp` - true positive
* `:fn` - false negative
* `:fp` - false positive
* `:tn` - true negative
raw docstring

binary-measures-all-calcclj

(binary-measures-all-calc {:keys [tp fp fn tn]
                           :or {tp 0.0 fp 0.0 fn 0.0 tn 0.0}})

Calculates the full battery of binary classification measures from a confusion matrix in a single pass.

This is a bulk, self-contained calculation of nearly every measure also available individually (accuracy, precision, mcc, kappa, etc., see measures) plus a few convenience keys not exposed as standalone functions (:cp/:cn/:pcp/:pcn as aliases of :p/:n/:pp/:pn, :f-measure as an alias of :f1-score, and :f-beta, an f-beta score function of one argument beta).

Parameters:

  • confusion-matrix (map): A map with :tp, :fp, :fn, :tn keys (numbers, missing keys default to 0.0), such as one returned by infer-confusion-matrix.

Returns a map containing every key in measures plus :cp, :cn, :pcp, :pcn, :f-measure, :f-beta.

Individual measures follow their own function's corner-case behavior, e.g. :mcc/:phi are ##NaN when their denominator is zero (see mcc).

See also measures (individual measure functions), binary-measures-thr (the same set of measures swept across score thresholds).

Calculates the full battery of binary classification measures from a confusion matrix in a single pass.

This is a bulk, self-contained calculation of nearly every measure also available
individually (`accuracy`, `precision`, `mcc`, `kappa`, etc., see [[measures]]) plus
a few convenience keys not exposed as standalone functions (`:cp`/`:cn`/`:pcp`/`:pcn`
as aliases of `:p`/`:n`/`:pp`/`:pn`, `:f-measure` as an alias of `:f1-score`, and
`:f-beta`, an f-beta score function of one argument `beta`).

Parameters:

- `confusion-matrix` (map): A map with `:tp`, `:fp`, `:fn`, `:tn` keys (numbers,
  missing keys default to `0.0`), such as one returned by [[infer-confusion-matrix]].

Returns a map containing every key in [[measures]] plus `:cp`, `:cn`, `:pcp`, `:pcn`,
`:f-measure`, `:f-beta`.

Individual measures follow their own function's corner-case behavior, e.g. `:mcc`/`:phi`
are `##NaN` when their denominator is zero (see [[mcc]]).

See also [[measures]] (individual measure functions), [[binary-measures-thr]]
(the same set of measures swept across score thresholds).
raw docstring

binary-measures-thrclj

(binary-measures-thr labels scores)
(binary-measures-thr labels scores true-value)

Calculates binary classification measures at every distinct score threshold, for building ROC/PR-style curves.

For each distinct value in scores, treats it as a decision threshold (predict positive when score >= threshold) and computes the resulting confusion matrix and derived measures. Observations that share the same score are treated as tied and distributed evenly within that threshold's step (fractional :tp/:fp/:fn/:tn counts can occur as a result).

Parameters:

  • labels (sequence): The true class labels, converted via binary-process-list (see true-value below).
  • scores (sequence of numbers): A score per label; higher scores are predicted positive at lower thresholds. Must be the same length as labels.
  • true-value (optional): Passed through to binary-process-list to determine which label values count as true.

Returns a map with :p, :n, :total, :prevalence (scalars) and per-threshold sequences (one entry per distinct score, from highest to lowest threshold) for :thr, :tp, :fp, :fn, :tn, and every rate/score measure (:accuracy, :error, :tpr/:recall/:sensitivity, :fnr/:miss-rate, :fpr/:fall-out, :tnr/:specificity, :ppv/:precision, :fdr, :for, :npv, :mcc, :f1-score, :kappa, :fm, :ts/:jaccard).

At the two ends of the threshold sweep, some of these sequences hit a 0/0 division; those boundary values are guarded to the nearest well-defined value (e.g. :ppv/:fdr at the highest threshold, :for/:npv at the lowest) rather than left as ##NaN, matching R precrec's convention for the same case.

See also binary-measures-all-calc (the same measures at a single, fixed confusion matrix rather than swept across thresholds).

Calculates binary classification measures at every distinct score threshold, for building ROC/PR-style curves.

For each distinct value in `scores`, treats it as a decision threshold (predict
positive when score >= threshold) and computes the resulting confusion matrix and
derived measures. Observations that share the same score are treated as tied and
distributed evenly within that threshold's step (fractional `:tp`/`:fp`/`:fn`/`:tn`
counts can occur as a result).

Parameters:

- `labels` (sequence): The true class labels, converted via [[binary-process-list]]
  (see `true-value` below).
- `scores` (sequence of numbers): A score per label; higher scores are predicted
  positive at lower thresholds. Must be the same length as `labels`.
- `true-value` (optional): Passed through to [[binary-process-list]] to determine
  which label values count as `true`.

Returns a map with `:p`, `:n`, `:total`, `:prevalence` (scalars) and per-threshold
sequences (one entry per distinct score, from highest to lowest threshold) for
`:thr`, `:tp`, `:fp`, `:fn`, `:tn`, and every rate/score measure (`:accuracy`,
`:error`, `:tpr`/`:recall`/`:sensitivity`, `:fnr`/`:miss-rate`, `:fpr`/`:fall-out`,
`:tnr`/`:specificity`, `:ppv`/`:precision`, `:fdr`, `:for`, `:npv`, `:mcc`,
`:f1-score`, `:kappa`, `:fm`, `:ts`/`:jaccard`).

At the two ends of the threshold sweep, some of these sequences hit a `0/0`
division; those boundary values are guarded to the nearest well-defined value
(e.g. `:ppv`/`:fdr` at the highest threshold, `:for`/`:npv` at the lowest) rather
than left as `##NaN`, matching R `precrec`'s convention for the same case.

See also [[binary-measures-all-calc]] (the same measures at a single, fixed
confusion matrix rather than swept across thresholds).
raw docstring

binary-process-listclj

(binary-process-list xs)
(binary-process-list xs true-value)

Convert binary labels to a true/false values.

Optional true-value when is:

  • nil - if labels are numbers, all non-zero values are treated as true. Otherwise each label is coerced with boolean (nil/false become false, anything else becomes true).
  • a sequence - all values in the sequence are treated as true.
  • a function - function is used to map true values, function should return true value (any value) and false/nil for false.
  • a value - just a single value.
Convert binary labels to a true/false values.

Optional `true-value` when is:

* `nil` - if labels are numbers, all non-zero values are treated as true. Otherwise each label is coerced with `boolean` (`nil`/`false` become `false`, anything else becomes `true`).
* a sequence - all values in the sequence are treated as true.
* a function - function is used to map true values, function should return true value (any value) and `false`/`nil` for false.
* a value - just a single value.
raw docstring

bmclj

(bm {:keys [tp fp fn tn]})
(bm tp fp fn tn)

Bookmaker informedness, BM

Bookmaker informedness, BM
raw docstring

csiclj

(csi {:keys [tp fp fn tn]})
(csi tp fp fn tn)

Jaccard index, threat score, TS, critical success index CSI

Jaccard index, threat score, TS, critical success index CSI
raw docstring

deltaPclj

(deltaP {:keys [tp fp fn tn]})
(deltaP tp fp fn tn)

Markedness, MK, deltaP

Markedness, MK, deltaP
raw docstring

dorclj

(dor {:keys [tp fp fn tn]})
(dor tp fp fn tn)

Diagnostic odds ratio

Diagnostic odds ratio
raw docstring

errorclj

(error {:keys [tp fp fn tn]})
(error tp fp fn tn)

Error

Error
raw docstring

f1-scoreclj

(f1-score {:keys [tp fp fn tn]})
(f1-score tp fp fn _tn)

F1 score, the harmonic mean of precision and recall: 2*tp/(2*tp+fp+fn).

Equivalent to ->f-beta with beta=1. See also ->f-inv-beta.

F1 score, the harmonic mean of precision and recall: `2*tp/(2*tp+fp+fn)`.

Equivalent to [[->f-beta]] with `beta=1`. See also [[->f-inv-beta]].
raw docstring

fall-outclj

(fall-out {:keys [tp fp fn tn]})
(fall-out _tp fp _fn tn)

False positive rate, FPR, fall-out

False positive rate, FPR, fall-out
raw docstring

fdrclj

(fdr {:keys [tp fp fn tn]})
(fdr tp fp fn tn)

False discovery rate

False discovery rate
raw docstring

fmclj

(fm {:keys [tp fp fn tn]})
(fm tp fp fn tn)

Fowlkes-Mallows index, FM

Fowlkes-Mallows index, FM
raw docstring

fnclj

(fn {:keys [_tp _fp fn _tn]})
(fn _tp _fp fn _tn)

False negative

False negative
raw docstring

fnrclj

(fnr {:keys [tp fp fn tn]})
(fnr tp fp fn tn)

False negative rate, FNR, miss-rate

False negative rate, FNR, miss-rate
raw docstring

forclj

(for {:keys [tp fp fn tn]})
(for _tp _fp fn tn)

False omission rate, FOR

False omission rate, FOR
raw docstring

fpclj

(fp {:keys [_tp fp _fn _tn]})
(fp _tp fp _fn _tn)

False positive

False positive
raw docstring

fprclj

(fpr {:keys [tp fp fn tn]})
(fpr tp fp fn tn)

False positive rate, FPR, fall-out

False positive rate, FPR, fall-out
raw docstring

gmeanclj

(gmean {:keys [tp fp fn tn]})
(gmean tp fp fn tn)

Geometric mean score, sqrt(specificity * recall)

Geometric mean score, sqrt(specificity * recall)
raw docstring

hit-rateclj

(hit-rate {:keys [tp fp fn tn]})
(hit-rate tp fp fn tn)

True positive rate, TPR, recall, sensitivity, hit-rate

True positive rate, TPR, recall, sensitivity, hit-rate
raw docstring

infer-confusion-matrixclj

(infer-confusion-matrix confusion-matrix)

Construct a confusion matrix from the input.

Returns a map with :tp, :fn, :fp and :tn keys.

Input can be one of:

  • a map with keys [:t :p], [:t :n], [:f :p] and [:f :n]
  • pair of pairs [[tp fn] [fp tn]]
  • a sequence of values [tp fn fp tn]
  • a confusion matrix
Construct a confusion matrix from the input.

Returns a map with `:tp`, `:fn`, `:fp` and `:tn` keys.  

Input can be one of:

* a map with keys [:t :p], [:t :n], [:f :p] and [:f :n]
* pair of pairs [[tp fn] [fp tn]]
* a sequence of values [tp fn fp tn]
* a confusion matrix
raw docstring

informednessclj

(informedness {:keys [tp fp fn tn]})
(informedness tp fp fn tn)

Bookmaker informedness, BM

Bookmaker informedness, BM
raw docstring

jaccardclj

(jaccard {:keys [tp fp fn tn]})
(jaccard tp fp fn _tn)

Jaccard index, threat score, TS, critical success index CSI

Jaccard index, threat score, TS, critical success index CSI
raw docstring

kappaclj

(kappa {:keys [tp fp fn tn]})
(kappa tp fp fn tn)

Cohen's kappa

Cohen's kappa
raw docstring

lr+clj

(lr+ {:keys [tp fp fn tn]})
(lr+ tp fp fn tn)

Positive likelihood ratio

Positive likelihood ratio
raw docstring

lr-clj

(lr- {:keys [tp fp fn tn]})
(lr- tp fp fn tn)

Negative likelihood ratio

Negative likelihood ratio
raw docstring

markednessclj

(markedness {:keys [tp fp fn tn]})
(markedness tp fp fn tn)

Markedness, MK, deltaP

Markedness, MK, deltaP
raw docstring

mccclj

(mcc {:keys [tp fp fn tn]})
(mcc tp fp fn tn)

Matthews correlation coefficient, MCC, phi

Returns ##NaN when any of tp+fp, tp+fn, tn+fp, tn+fn is zero (the denominator is undefined), matching R's metrica::mcc convention. Note this differs from scikit-learn's matthews_corrcoef, which returns 0.0 (with a warning) in that case.

Matthews correlation coefficient, MCC, phi

Returns `##NaN` when any of `tp+fp`, `tp+fn`, `tn+fp`, `tn+fn` is zero (the
denominator is undefined), matching R's `metrica::mcc` convention. Note this
differs from scikit-learn's `matthews_corrcoef`, which returns `0.0` (with a
warning) in that case.
raw docstring

measuresclj

Map from measure keyword to its corresponding function.

Every value is a function accepting either a confusion-matrix map (:tp/:fp/:fn/:tn keys) or the four counts as separate arguments (tp fp fn tn), returning a double.

Useful for looking up a measure function by name, e.g. ((measures :mcc) confusion-matrix).

See also binary-measures-all-calc (computes every measure in one pass) and infer-confusion-matrix (builds the confusion-matrix map this expects).

Map from measure keyword to its corresponding function.

Every value is a function accepting either a confusion-matrix map (`:tp`/`:fp`/`:fn`/`:tn`
keys) or the four counts as separate arguments (`tp fp fn tn`), returning a `double`.

Useful for looking up a measure function by name, e.g. `((measures :mcc) confusion-matrix)`.

See also [[binary-measures-all-calc]] (computes every measure in one pass) and
[[infer-confusion-matrix]] (builds the confusion-matrix map this expects).
raw docstring

miss-rateclj

(miss-rate {:keys [tp fp fn tn]})
(miss-rate tp fp fn tn)

False negative rate, FNR, miss-rate

False negative rate, FNR, miss-rate
raw docstring

mkclj

(mk {:keys [tp fp fn tn]})
(mk tp fp fn tn)

Markedness, MK, deltaP

Markedness, MK, deltaP
raw docstring

nclj

(n {:keys [tp fp fn tn]})
(n _tp fp _fn tn)

Real negative

Real negative
raw docstring

npvclj

(npv {:keys [tp fp fn tn]})
(npv tp fp fn tn)

Negative predictive value

Negative predictive value
raw docstring

pclj

(p {:keys [tp fp fn tn]})
(p tp _fp fn _tn)

Real positive

Real positive
raw docstring

p4clj

(p4 {:keys [tp fp fn tn]})
(p4 tp fp fn tn)

P4 metric,

P4 metric, 
raw docstring

phiclj

(phi {:keys [tp fp fn tn]})
(phi tp fp fn tn)

Matthews correlation coefficient, MCC, phi. Alias of mcc -- see its docstring for the ##NaN-on-degenerate-input behavior.

Matthews correlation coefficient, MCC, phi. Alias of [[mcc]] -- see its
docstring for the `##NaN`-on-degenerate-input behavior.
raw docstring

pnclj

(pn {:keys [tp fp fn tn]})
(pn _tp _fp fn tn)

Predicted negative

Predicted negative
raw docstring

ppclj

(pp {:keys [tp fp fn tn]})
(pp tp fp _fn _tn)

Predicted positive

Predicted positive
raw docstring

ppvclj

(ppv {:keys [tp fp fn tn]})
(ppv tp fp fn tn)

Precision, positive predictive value, PPV

Precision, positive predictive value, PPV
raw docstring

precisionclj

(precision {:keys [tp fp fn tn]})
(precision tp fp _fn _tn)

Precision, positive predictive value, PPV

Precision, positive predictive value, PPV
raw docstring

prevalenceclj

(prevalence {:keys [tp fp fn tn]})
(prevalence tp fp fn tn)

Prevalence, p/(p+n)

Prevalence, p/(p+n)
raw docstring

ptclj

(pt {:keys [tp fp fn tn]})
(pt tp fp fn tn)

Prevalence threshold

Prevalence threshold
raw docstring

recallclj

(recall {:keys [tp fp fn tn]})
(recall tp _fp fn _tn)

True positive rate, TPR, recall, sensitivity, hit-rate

True positive rate, TPR, recall, sensitivity, hit-rate
raw docstring

selectivityclj

(selectivity {:keys [tp fp fn tn]})
(selectivity tp fp fn tn)

True negative rate, TNR, specificity, selectivity

True negative rate, TNR, specificity, selectivity
raw docstring

sensitivityclj

(sensitivity {:keys [tp fp fn tn]})
(sensitivity tp fp fn tn)

True positive rate, TPR, recall, sensitivity, hit-rate

True positive rate, TPR, recall, sensitivity, hit-rate
raw docstring

specificityclj

(specificity {:keys [tp fp fn tn]})
(specificity tp fp fn tn)

True negative rate, TNR, specificity, selectivity

True negative rate, TNR, specificity, selectivity
raw docstring

tnclj

(tn {:keys [_tp _fp _fn tn]})
(tn _tp _fp _fn tn)

True negative

True negative
raw docstring

tnrclj

(tnr {:keys [tp fp fn tn]})
(tnr tp fp fn tn)

True negative rate, TNR, specificity, selectivity

True negative rate, TNR, specificity, selectivity
raw docstring

totalclj

(total {:keys [tp fp fn tn]})
(total tp fp fn tn)

Total

Total
raw docstring

tpclj

(tp {:keys [tp _fp _fn _tn]})
(tp tp _fp _fn _tn)

True positive

True positive
raw docstring

tprclj

(tpr {:keys [tp fp fn tn]})
(tpr tp fp fn tn)

True positive rate, TPR, recall, sensitivity, hit-rate

True positive rate, TPR, recall, sensitivity, hit-rate
raw docstring

tsclj

(ts {:keys [tp fp fn tn]})
(ts tp fp fn tn)

Jaccard index, threat score, TS, critical success index CSI

Jaccard index, threat score, TS, critical success index CSI
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close