Nous.Eval.Guard.Metrics (nous v0.21.1)

Copy Markdown View Source

Guard metrics over replayed outcomes (Nous.Eval.Guard.Recording.outcome/0).

"Positive" means the case should be blocked (label: :block). Cases whose guard call errored sit in their own row of the confusion matrix and are left out of every rate except the error rate: an error is never folded into a deny (an erroring guard denies by default, which would flatter its false-allow rate).

An escalation's outcome depends on the deployment, so it is counted both ways:

  • escalate ⇒ block (_eb): no handler approves it; the default resolution
  • escalate ⇒ allow (_ea): a human or handler approves it; the worst case

and the escalation rate is reported as the human load.

summarize/2 returns:

  • :n, :n_block, :n_allow, :n_error, :groups
  • :confusion - %{block: %{allow, escalate, deny}, allow: %{...}, error: %{block, allow}}
  • rates, each %{estimate, ci, successes, n} (Wilson, nil when its denominator is empty): :far_eb / :far_ea (false-allow rate, i.e. 1 − recall), :fpr_eb / :fpr_ea (false-block rate), :hard_negative_fpr (benign cases tagged hard_negative, escalate ⇒ block), :escalation_rate, :error_rate (over every case)
  • :precision, :f1 - at the corpus prevalence (escalate ⇒ block)
  • :prevalence - production prevalence π used below (option, else the corpus share); :ppv / :npv at π (Wilson bounds of TPR and FPR plugged into the monotone formulas for a conservative interval) and :benign_blocked_per_1000 = 1000·FPR·(1 − π)
  • :threshold_free - from the scalar scores (errors left out): :pr_auc (average precision), :roc_auc, :recall_at_fpr (%{max_fpr, recall, fpr, threshold}), :cost_threshold (the cost-weighted score threshold, Nous.Eval.Stats.Classifier.cost_weighted_threshold/2); nil entries when the scores or a class are missing
  • :warnings - a Wilson half-width above 5 pp, and an FPR target finer than one benign case (1 / n_allow)

Options: :prevalence, :max_fpr (default 0.01), :cost_false_allow (default 10.0), :cost_false_block (default 1.0), :confidence (default 0.95).

Summary

Functions

Metrics for outcomes (see the moduledoc).

Functions

summarize(outcomes, opts \\ [])

@spec summarize([map()], keyword()) :: map()

Metrics for outcomes (see the moduledoc).