The Lawfare Academy

Lawfare Group → Knowledge Institute → Lawfare Academy

← Back to program

← CS 230 — Mathematics, Statistics and Data for AI

Weeks 15–16

Decision metrics and a reproducible data report

Learning objectives

  • Explain and trace the mechanisms in decision metrics and a reproducible data report.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

Current study directions: use the original Academy preparation chapters, preserved teaching and complete optional worked reasoning on LawfareGroup.com. Retained attributed readings, source exercises and historical assignment directions are optional further study. This notice supersedes earlier textbook-supported directions preserved below and in historical companions. Independent subject review and observed learner testing remain pending.

A metric is a choice about what counts as error. Accuracy weights every classification equally, which can obscure rare but important outcomes. A model that predicts no defects on a dataset with one percent defects achieves 99 percent accuracy while finding none. Compare a model with a baseline matched to the task and report class-specific behavior.

Thresholds convert scores into decisions. Changing a threshold often trades precision against recall. Select it using development data and operational costs, not by repeatedly optimizing on a final test set. If an alert requires manual review, capacity limits matter: a detector producing ten thousand alerts for a team that can examine fifty may be unusable even when its ranking looks good.

A reproducible report specifies the task, data grain, inclusion rules, split, transformations, metric definitions and uncertainty. Keep test labels reserved until choices are settled. If results prompt redesign, acknowledge that the test set has become development evidence and obtain a fresh final evaluation where possible. Present subgroup and time-period results when relevant, with denominators; a percentage without a count can hide fragile conclusions.

Worked reasoning The model correctly flags eight of twenty positives, so recall is only 40 percent. Eight of ten alerts are correct, giving 80 percent precision. Overall accuracy is 86 percent. A predictor that always chooses negative scores 80 percent accuracy here but zero recall; the chosen model improves detection, although whether it is useful depends on missed-event and review costs.

Extended teaching and laboratory

A confusion matrix describes counts at a chosen decision threshold. Accuracy, precision and recall summarize different denominators. Decision usefulness also requires costs, capacity and the consequences of false positives and false negatives. A high score on one metric does not establish a superior operational policy.

Threshold selection belongs in development, followed by evaluation on held-out data. Report the population and threshold with each matrix. A different prevalence or review process can change the practical value even if a reported aggregate score looks similar.

Worked problem System A has TP=30, FP=10, FN=20, TN=140. Each missed positive costs 100 units and each false alert costs 5. Compute accuracy, precision, recall and error cost.

Step-by-step reasoning 1. There are 200 cases. Accuracy=(30+140)/200=85%. Precision=30/40=75%; recall=30/50=60%.

  1. Miss costs total 20×100=2000. False-alert costs total 10×5=50. The stated error cost is 2050 units.
  1. An always-negative system has 150/200=75% accuracy and costs 50×100=5000. Accuracy alone hides the decision benefit.
  1. The cost calculation omits review labor for true alerts and intervention effects unless explicitly included. Do not label it total business profit.

Information measures require actual probability distributions

For a discrete outcome of positive probability p, self-information is −log₂p bits. A probability-one outcome carries zero surprise under that model; an outcome assigned probability 1/8 carries three bits. Entropy averages this quantity over outcomes: H(P)=−Σpᵢlog₂pᵢ. Define a zero-probability contribution as zero by continuity, rather than discarding arbitrary invalid numbers. A finite k-category distribution has entropy between zero and log₂k, with the upper bound attained by equal probabilities. This measures modeled uncertainty, not truth, usefulness or human understanding.

A fictional job-type distribution P=[1/2,1/4,1/4] has entropy (1/2)×1+(1/4)×2+(1/4)×2=1.5 bits. Under an equal three-category coding model Q=[1/3,1/3,1/3], cross-entropy CE(P,Q)=−Σpᵢlog₂qᵢ=log₂3≈1.584963 bits. It is the average log penalty when observations follow P and predictions use Q. Its excess over H(P) is approximately .084963 bits. Entropy can be understood as an idealized asymptotic coding limit; it need not be an integer length assigned to each individual symbol.

Kullback–Leibler divergence D(P||Q)=Σpᵢlog₂(pᵢ/qᵢ) equals CE(P,Q)−H(P). It is nonnegative for valid normalized distributions on the same outcome space, and zero precisely when the distributions agree. It is generally asymmetric and is not a metric satisfying all ordinary distance axioms. If pᵢ>0 but qᵢ=0, the divergence and cross-entropy are infinite. A numerical implementation must handle that support mismatch explicitly. Taking an absolute value does not repair an invalid negative result, and skipping NaNs can conceal negative inputs or malformed probabilities.

For P=[.75,.25] and Q=[.5,.5], D(P||Q)=.75log₂1.5+.25log₂.5≈.188722 bits. In reverse, D(Q||P)=.5log₂(2/3)+.5log₂2≈.207519 bits. These different values illustrate directionality using genuine distributions. A list of sampled normal observations contains measurements, potentially negative ones; it is not a list of category probabilities. Sorting those observations and inserting them into a discrete KL formula does not estimate divergence between normal distributions. Construct justified densities, probabilities or a suitable estimator instead.

Joint, conditional and mutual information

A joint probability table describes paired outcomes. Derive each marginal by summing the appropriate rows or columns; do not supply unrelated vectors. Joint entropy averages −log₂p(x,y). Conditional entropy H(Y|X) averages the entropy of Y's conditional distributions using the actual probabilities of X. For discrete variables, H(X,Y)=H(X)+H(Y|X). Mutual information I(X;Y)=Σx,y p(x,y)log₂[p(x,y)/(p(x)p(y))] equals H(X)+H(Y)−H(X,Y). It is nonnegative and vanishes for independence. A pointwise log ratio can be negative; nonnegativity applies to its correctly weighted average.

If X is a fair binary variable and Y is an exact copy, the joint table has .5 at (0,0) and .5 at (1,1). Both marginal entropies are one bit, joint entropy is one, conditional entropy is zero and mutual information is one. If Y is an independent fair bit, all four joint cells are .25: joint entropy is two, conditional entropy is one and mutual information is zero. A duplicate field therefore contributes no new information despite occupying another column. Mutual information concerns dependence, including nonlinear dependence; it does not identify a causal direction.

Relate the measure to learning and its limits

For a categorical label y and predicted probability vector q, one-example cross-entropy in natural units is −ln q[y]. Average it over a declared evaluation sample to obtain empirical mean negative log-likelihood. For target labels [0,1] and predictions [.8,.2] and [.4,.6], the mean is −ln(.8×.6)/2≈.366985 nats. State whether a report uses a sum or mean, and natural or base-two logarithms. Perplexity is exp(mean loss) for natural logs, or 2 raised to mean loss in bits. Comparisons require the same outcomes, tokenization, weighting and test population; lower loss is not a guarantee that every decision improved.

Differential entropy h(X)=−∫f(x)log f(x)dx describes densities and differs from discrete entropy. It can be negative and changes with coordinates: for nonzero a, h(aX)=h(X)+log|a| when defined. For a uniform density on an interval of length 1/4, differential entropy in bits is log₂(1/4)=−2. Discrete joint-entropy lower bounds cannot be transplanted without checking their continuous hypotheses. KL divergence compares corresponding distributions under a common change of coordinates; individual differential entropies need not be invariant.

Optional changed record: verify the inputs before interpreting a number

Change the job-type distribution to P=[1/2,1/2,0], retaining uniform Q. Calculate entropy, cross-entropy and KL. Then replace Q with [.5,.5,0]. Finally suppose Y=X for a biased binary X with probability .25 of one. Determine mutual information.

The changed P has entropy one bit. Against uniform Q, cross-entropy remains log₂3, so KL is log₂3−1≈.584963 bits. Against Q=P, only the two positive-support outcomes contribute, giving cross-entropy one and KL zero. The shared zero category contributes zero; it is not an infinite mismatch. If instead P assigned positive mass there while Q stayed zero, the divergence would be infinite. For the copied biased bit, H(X)=−.25log₂.25−.75log₂.75≈.811278 bits, joint entropy equals that value and conditional entropy is zero. Mutual information is therefore .811278, not one: a perfect copy shares all of the available uncertainty, which need not be one bit.

Optional criteria: validate support and normalization; retain the chosen logarithm units; derive marginals and distinguish pointwise from average information; explain why a computed loss or dependence measure does not establish truth or causality. Award one point for each fully explained criterion.

Apply the idea

System A has TP=30, FP=10, FN=20, TN=140. Each missed positive costs 100 units and each false alert costs 5. Compute accuracy, precision, recall and error cost.

System B has TP=40, FP=40, FN=10, TN=110 under the same costs. Compare error costs and identify a capacity question.

Read the worked reasoning

B costs 10×100+40×5=1200, less than A’s 2050, despite lower accuracy of 75%. B generates 80 alerts versus A’s 40. If reviewers can handle only 50, the unconstrained cost comparison does not establish deployability. Evaluate a threshold or workflow under the actual capacity constraint.

Check understanding

Why reserve a final test set?

  1. To tune every threshold repeatedly
    Feedback

    Threshold tuning belongs in development or validation.

  2. To ensure future data can never change
    Feedback

    A test estimates a specified setting, not all future environments.

  3. To estimate performance after development choices are fixed
    Feedback

    Repeated adaptation to test results makes them development evidence.

Further reading

Current study directions: use the original Academy preparation chapters, preserved teaching and complete optional worked reasoning on LawfareGroup.com. Retained attributed readings, source exercises and historical assignment directions are optional further study. This notice supersedes earlier textbook-supported directions preserved below and in historical companions. Independent subject review and observed learner testing remain pending.

Read the original on-site preparation chapter and preserved investigation. Work the changed record before opening its full model. Earlier source assignment directions remain in immutable edition4.

My learning →