Module 6 · Probability and Random Variables Lesson 55 of 120

Bayes’ Theorem and Base Rates

Why a good fraud detector can still generate many false alarms.

2:35 clip2:54:58–2:57:33 in the full courseWatch on YouTube

Transcript

23 sentences · select one to jump there

Check your understanding

How many false flags arise in the 10,000-transaction example?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

055-bayes-theorem-and-base-rates.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 055 of 120
 * Bayes’ Theorem and Base Rates
 * Module 06: Probability and Random Variables
 *
 * Scenario: Why a good fraud detector can still generate many false alarms
 * Rule:     posterior = sensitivity·prior / [sensitivity·prior + FPR·(1−prior)]
 *
 * Try it:   How many false flags arise in the 10,000-transaction example?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/bayes-theorem-and-base-rates/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson055() {
  const prior=.01, sensitivity=.90, falsePositiveRate=.05;
  const truePositiveMass=sensitivity*prior;
  const falsePositiveMass=falsePositiveRate*(1-prior);
  const result = truePositiveMass/(truePositiveMass+falsePositiveMass);
  return result;
}

export const checkedResult = 0.15384615384615385;

// Run this file directly: npx tsx lessons/06-probability-and-random-variables/055-bayes-theorem-and-base-rates.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson055(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

0.15384615384615385

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

posterior = sensitivity·prior / [sensitivity·prior + FPR·(1−prior)]