GithubHelp home page GithubHelp logo

dsc-chi-warmup-bayes's Introduction

Practice with Bayes

Thomas Bayes Bayes Theorum
# Run this cell unchanged.
from test import Test
test = Test()

#1 Write a function

Define a function called bayes that receive 3 parameters:

  1. b_given_a
  2. a
  3. b

And returns the probability for A|B

# Your code here
def bayes():
    pass

#2 You've Got Mail!

📩You receive an email and your spam detector has classified the email as spam.📩

Assume that:

  • 5% of emails you receive are spam
  • The spam detector correctly identifies spam 99% of the time
  • Emails are incorrectly marked as spam 0.2% of the time.

Hint

P(B) = P(B|A) × P(A) + P(B|not A) × P(not A) = P(Detected) = P(Detected|Spam) × P(Spam) + P(Detected|not Spam) × P(not Spam)

What is the probability the email is spam?

# Your code here
b_given_a = None
a = None
b = None
a_given_b = bayes(b_given_a, a, b)

Run the cell below to check your answer

(Do not round your answer)

test.run_test(a_given_b, 'spam')

#3 Weather Weather Weather

☁️You wake up and the sky is cloudy☁️

  • There is a 30% chance of it raining on any given day 💧
  • On days when it rains there is a 95% chance of it being cloudy 🌧️
  • On days when it does not rain, 25% of the time there are dark clouds in the sky.

What is the probability that it will rain?

# Your code here
b_given_a = None
a = None
b = None
a_given_b = bayes(b_given_a, a, b)

Run the cell below to check your answer

test.run_test(a_given_b, 'rain')

#4 Parenthood

You are on a jury considering a paternity suit. The mother has blood type O, and the alleged father has blood type AB.

A blood test shows that the child has blood type B. What is the chance that the alleged father is in fact the real father, given that the child has blood type B?

Here's some information we need to solve the problem. According to genetics, there is a 50% chance that this child will have blood type B if this alleged father is the real father, and based on rates of B genes in the population, there is a 9% chance that this child would have blood type B if this alleged father is not the real father.

Based on other evidence (e.g., testimonials, physical evidence, records) presented before the DNA test, you believe there is a 75% chance that the alleged father is the real father. This assessment is your prior belief. Now, we need to use Bayes Rule to update it for the results of the child's blood test.

# Your code here
b_given_a = None
a = None
b = None
a_given_b = bayes(b_given_a, a, b)

Run the cell below to check your answer

test.run_test(a_given_b, 'father')

dsc-chi-warmup-bayes's People

Contributors

joelsewhere avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.