Module 6 · Probability and Random Variables Lesson 53 of 120

Conditional Probability

Changing the denominator after a fraud flag.

2:30 clip2:49:49–2:52:20 in the full courseWatch on YouTube

Transcript

20 sentences · select one to jump there

Check your understanding

Are P(fraud|flag) and P(flag|fraud) generally equal?

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.

053-conditional-probability.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 053 of 120
 * Conditional Probability
 * Module 06: Probability and Random Variables
 *
 * Scenario: Changing the denominator after a fraud flag
 * Rule:     P(F|A)=P(F∩A)/P(A)
 *
 * Try it:   Are P(fraud|flag) and P(flag|fraud) generally equal?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/conditional-probability/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson053() {
  const transactions=10000, flagged=500;
  const fraudAndFlagged=50, allFraud=100;
  const result = {fraudGivenFlag:fraudAndFlagged/flagged,
    flagGivenFraud:fraudAndFlagged/allFraud,
    joint:fraudAndFlagged/transactions};
  return result;
}

export const checkedResult = {"fraudGivenFlag":0.1,"flagGivenFraud":0.5,"joint":0.005};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "fraudGivenFlag": 0.1,
  "flagGivenFraud": 0.5,
  "joint": 0.005
}

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

Lesson notes

The rule

P(F|A)=P(F∩A)/P(A)