UPI Study › Courses › Introduction to Artificial Intelligence › Free lessons › Lesson 4.2 Free with a free account
Applying Bayes' Rule to AI Decisions
Introduction to Artificial Intelligence · Chapter 4: Search, Heuristics, and Game StrategySection 4.2 · lesson 24 of 6913 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Artificial Intelligence.
Lesson complete
Earn the 3 college credits for Introduction to Artificial Intelligence
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Blind and Competitive Search Strategies →← Handling Uncertainty and Measurement in Scientific WorkNext lesson: Blind and Competitive Search Strategies →
In this lesson
Update beliefs with evidence and avoid the base-rate fallacy.
- Derive Bayes' rule from conditional probability and name its parts
- Calculate posterior probabilities for medical tests, spam filters, and fraud detectors
- Explain the base-rate fallacy and apply step-by-step Bayesian updating
- Compare maximum a posteriori and maximum likelihood decisions
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,673 words). Read along, or search it.
Opening Puzzle
A 90 Percent Accurate Test
A test for a rare disease is 90 percent accurate. Your result comes back positive. How worried should you be? Most people say: about 90 percent sure I'm ill. For this test, the true answer is only about 9 percent. Studies of doctors found the same mistake. And AI faces it all the time. A spam filter sees the word free. A fraud detector sees an odd purchase. A game program sees a raise. Each must decide how much to believe, after uncertain evidence. The tool for that is Bayes' rule.
Worked Example
A Mailbox of 1,000 Emails
Start with a mailbox of 1,000 emails. 300 are spam, and 700 are not. Of the spam, 240 contain the word free, and 60 don't. Of the good email, 35 contain free, and 665 don't. That's 275 with free, in all. A probability runs from 0, impossible, to 1, certain. P of spam is 300 out of 1,000: 0.30. Likewise, P of free is 0.275. And both at once, P of spam and free, is 240 out of 1,000: 0.24.
Definition
Conditional Probability and Its Order
Now a new question. Among only the emails with free, what share are spam? Look only at the 275 free emails: 240 of them are spam. That's a conditional probability. P of A given B is P of A and B, divided by P of B. It counts only the cases where B is true. Check it: 0.24 over 0.275 is 0.873. But order matters. P of free given spam is 240 over 300: 0.80. Mixing up the two is a classic mistake.
Derivation
Bayes' Rule in Three Steps
Bayes' rule falls out of that definition in three steps. Call the hypothesis H, and the evidence E. Step one: write the definition both ways. P of H given E is the joint, P of H and E, over P of E. And P of E given H is that same joint, over P of H. Step two: rearrange the second. The joint equals P of E given H, times P of H. Step three: substitute it into the first. That's Bayes' rule: P of H given E equals P of E given H, times P of H, over P of E.
Evidence Term
Building P of E From Two Cases
Why is this useful? Often we know one direction, and want the other. A lab tests its method on sick people, so it knows P of positive given sick. A patient wants P of sick given positive. The bottom, P of E, is rarely given. Build it from the two ways the evidence can happen: with H true, or with H false. For the mailbox: 0.80 times 0.30, plus 0.05 times 0.70, is 0.275.
Key Terms
Prior, Likelihood, Evidence, and Posterior
Each part of the rule has a name. The prior, P of H, is the belief before the evidence: here, 0.30. The likelihood, P of E given H, is how well H predicts the evidence: 0.80. The evidence term, P of E, is how likely that is overall, 0.275. It scales the answer so the probabilities add to 1. And the posterior, P of H given E, is the updated belief: 0.873. In words: posterior equals likelihood times prior, over evidence.
Odds Shortcut
Likelihood Ratio Times Prior Odds
Free is 16 times likelier in spam than in good mail: 0.80 over 0.05. That's the likelihood ratio: how strongly the evidence favors H. The shortcut: posterior odds are prior odds, times that ratio. 0.30 against 0.70 is about 0.43. Unrounded, 0.4286 times 16 is 6.86. As a probability, 6.86 over 7.86 is 0.873 again. Updating becomes a single multiplication.
Worked Example
A Rare Disease Gives 9.2 Percent
Now the test from the opening. A disease affects 1 percent of people. If you have it, the test is positive 90 percent of the time. That's its sensitivity. If you don't, it's still positive 9 percent of the time. That's the false-positive rate. Step by step. The prior is 0.01. The likelihoods are 0.90 and 0.09. The evidence: 0.90 times 0.01, plus 0.09 times 0.99. That's 0.009 plus 0.0891: 0.0981. The posterior: 0.009 over 0.0981 is 0.0917. About 9.2 percent.
Natural Frequencies
Picturing 10,000 People and the Base-Rate Fallacy
Percentages feel slippery, so picture 10,000 real people. Only 100 have the disease, and 90 of them test positive. But 9,900 are healthy, and 9 percent of them, 891 people, test positive too. So there are 981 positives, and only 90 of them are truly ill. That's 9.2 percent. Ignoring how common something is, the prior, is the base-rate fallacy. The many healthy people make more false alarms than the few sick make true ones.
Base Rates
Same Test, Different Base Rates
The same test means very different things at different base rates. If 1 person in 1,000 has it, a positive result means about a 1 percent chance. At 1 in 100, it's 9.2 percent. At 1 in 10, it's 52.6 percent. And at 1 in 2, it's 90.9 percent. The test never changed. Only the base rate did.
Quick Check
A Screening Test at 2 Percent Prevalence
Quick check. A new screening test catches 95 percent of the people who have a condition. It also flags 10 percent of the people who don't. And the condition affects 2 percent of the people tested. Someone tests positive. About how likely is it that they have the condition? Pause, and decide. A: about 16 percent. Picture 1,000 people. 20 have the condition, and 19 of them test positive. Of the 980 who don't, 10 percent, 98 people, test positive too. So only 19 of 117 positives are real: about 16 percent. 95 percent is tempting, but that's the chance of a positive given the condition: the reverse question. The low base rate drags the answer down.
AI Application
Fraud Alerts and False Alarms
Every detector for something rare faces the same issue. Say 1 transaction in 1,000 is fraud. A detector flags 95 percent of fraud, and raises a false alarm on 2 percent of honest purchases. The chance of fraud given an alert is 0.00095 over 0.02093: about 0.045. Only about 1 alert in 22 is real fraud. An accurate detector can still bury its users in false alarms.
AI Application
Spam Filters Weigh the Prior
Spam works the same way. Where only 5 percent of mail is spam, free gives 45.7 percent: close to a coin toss. In our 30 percent mailbox, 87.3. At 70 percent, 97.4. At 90, 99.3. So a good filter weighs the evidence against how common spam is.
Bayesian Updating
Each Posterior Becomes the Next Prior
Evidence rarely arrives all at once. Bayesian updating treats each posterior as the prior for the next piece of evidence. Back to the medical test: after one positive, 9.2 percent. A second test, from a lab with independent mistakes, is also positive. Now the prior is 0.0917. The evidence is 0.90 times that, plus 0.09 times 0.9083. That's 0.0826 plus 0.0817: 0.1643. The posterior is 0.0826 over 0.1643: about 50 percent.
Odds Shortcut
Three Positives Multiply the Odds
So the belief climbs from 1 percent, to 9.2, to about 50. A third positive lifts it to about 91 percent. The odds shortcut makes this easy. Each positive multiplies the odds by the same ratio: 0.90 over 0.09, or 10. Odds of 1 to 99, times 10 three times, come to about 10 to 1: 91 percent. A negative first result would instead cut it to about 0.1 percent.
Cautions
Independence and Priors of Zero or One
Some cautions. Strong evidence moves beliefs more. And independent evidence gives the same answer in any order. But independence is an assumption: the same flawed test may repeat its own mistake. And never start from a prior of exactly 0 or 1. Multiplied by anything, 0 stays 0, so that belief could never change.
Decision Rules
MAP Versus Maximum Likelihood
Often the goal is a decision. The maximum a posteriori rule, MAP, picks the hypothesis with the highest posterior. P of E is the same for every hypothesis, so MAP just compares likelihood times prior. Maximum likelihood, ML, picks whatever makes the evidence most likely, and ignores the prior. The two agree only when the priors are equal. Three machines make parts, and a defective part turns up. Machine A makes 70 percent of the parts, B makes 20, and C makes 10. Their defect rates are 1, 2, and 5 percent. The products are 0.0070, 0.0040, and 0.0050. ML picks C, the sloppiest machine. But MAP picks A. It makes so many parts that its few defects add up. Dividing by the total, 0.016, gives A about 44 percent. That's the most probable machine, not a sure one: C still has 31 percent. MAP is everywhere. To a speech recognizer, recognize speech sounds like wreck a nice beach. The first phrase is far more common, so MAP picks it. A card player who bluffs on 20 percent of hands raises with 90 percent of bluffs, and half of strong hands. So a raise is a bluff only 31 percent of the time. One limit: MAP ignores what a mistake costs. After one positive test, MAP says probably healthy. Still, test again: a missed disease costs far more.
Quick Check
Diagnosing a Stalled Robot Arm
Quick check. A robot arm stalls. Three faults could explain it. A worn gear has a prior of 0.6, and causes a stall 10 percent of the time. A loose wire has a prior of 0.3, and causes a stall 30 percent of the time. A bad chip has a prior of 0.1, and causes a stall 50 percent of the time. Which fault does MAP pick? Pause, and decide. B, the loose wire. Multiply each prior by its stall rate. The gear gives 0.06, the wire 0.09, and the chip 0.05. The wire's product is largest. Divided by the total, 0.20, its posterior is 45 percent. The chip is the tempting ML answer, and the gear is the most common fault. But MAP weighs both, and neither wins alone.
Key Takeaways
Priors, Posteriors, and MAP Summed Up
To sum up. Bayes' rule comes from conditional probability, and turns P of E given H into P of H given E. The prior, the likelihood and the evidence give the posterior. Ignoring the base rate is a fallacy: rare conditions make most alarms false. Update step by step, each posterior becoming the next prior. And MAP picks the most probable hypothesis, whatever a mistake would cost.
Reflection
Alerts From an Airport Face Scanner
Something to think about. An airport face scanner is 99 percent accurate. Among millions of travelers, only a handful are on a watch list. What would you expect of its alerts, and how should staff treat them?
About Introduction to Artificial Intelligence at UPI Study
Introduction to Artificial Intelligence (Computer Science 373) is a self-paced online course of 69 video lessons in 9 chapters, from intelligent agents and search to game strategy, neural networks, logic and reasoning, machine learning, language, robotics and AI ethics. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: AI vs Current Trends in CS and IT
Why take it here
Why students take Introduction to Artificial Intelligence with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Artificial Intelligence carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Applying Bayes' Rule to AI Decisions
What is Bayes' rule in simple terms?
What is the base-rate fallacy?
How does Bayesian updating work with more than one piece of evidence?
What is the difference between MAP and maximum likelihood estimation?
About the Introduction to Artificial Intelligence course
How many college credits is Introduction to Artificial Intelligence?
How much does Introduction to Artificial Intelligence cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Artificial Intelligence take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Artificial Intelligence.
69 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
3 credits · NCCRSEnroll →