5 hidden checks

Three small functions that turn this unit's formulas into code.

  • posterior(prior, sensitivity, fpr): the probability of having the condition given a positive test. prior is the prevalence, sensitivity is , fpr is .
  • gaussian_mle(x): return (mu, sigma), the maximum likelihood estimates for a 1-D array of samples. MLE divides by .
  • bernoulli_nll(p, flips): the negative log-likelihood of an array of 0/1 flips under probability p of a 1. Use np.log.
checks
  • posterior reproduces the lesson's examplenot run
  • posterior handles other casesnot run
  • gaussian_mle returns the mean and the divide-by-n spreadnot run
  • bernoulli_nll is the sum of -log probabilitiesnot run
  • the NLL is smallest at the observed fractionnot run
python sleeps until you press run

Press Run & check. Your code runs first, then the hidden checks on the left.