GithubHelp home page GithubHelp logo

ds-prob-via-outcomes-lab's Introduction

Lab: probability via outcomes

Key point of this lab: if we have a sample space where each outcome is equally likely:

$P(\text{each outcome}) = \dfrac{1}{\mid S \mid}$

where $\mid S \mid$ is the cardinality of $S$, in other words, the number of possible outcomes in the sample space. then

$P(E) = \dfrac{ \text{number of outcomes in E} }{\text{number of outcomes in S}}= \dfrac{\mid E \mid}{\mid S \mid}$

Exercise 1

In this exercise, we'll look at possible outcomes when throwing a dice twice.

Next, we'll compute a couple or probabilities associated with doing this. First, let's create the sample set as a numpy array below.

import numpy as np
sample_dice = None

Look at the shape of the array to reassure we haven't made any mistakes.

None # should be equal to (36,2)

Use Python to obtain the following probabilities:

a. What is the probability of throwing a 5 at least once?

First, use sample_dice to get "True" values for each time a 5 occurs.

set_5 = None

Next, make sure that you get a value True for each pair where at least one 5 was thrown.

true_5 = None
print(true_5)

Applying the sum() function you can get to the total number of items in the event space. Divide this by the total number in the sample space.

prob_5 = None
print(prob_5)

b. What is the probability of throwing a 5 or 6 at least once?

set_5 = None
set_6 = None
set_5_6 = None
set_any_5_6 = None
print(set_any_5_6) 
prob_5_6 = None
print(prob_5_6)

c. What is the probability of the outcome having a sum of exactly 8?

sum_dice = None
sum_8 = None
prob_sum_8 = None
print(prob_sum_8)

Exercise 2

At a supermarket, we randomly select customers, and make notes of whether a certain customer owns a Visa card (event A) or an Amex credit card (event B). Some customers own both cards. You can assume that:

  • P(A) = 0.5
  • P(B) = 0.4
  • both A and B = 0.25.
  1. compute the probability that a selected customer has at least one credit card.

  2. compute the probability that a selected customer doesn't own any of the mentioned credit cards.

  3. compute the probability that a customer only owns VISA card.

(You can use python here, but you don't have to)

Exercise 3

A teaching assistant is holding office hours so students can make appointments. She has 6 appointments scheduled today, 3 by male students, and 2 by female students.

import numpy as np

NOTE: pretty brutal having them type it by hand, but will prove the point of what they'll see later

sample_mf= None
None # get the shape of sample_mf
sample_length= None
print(sample_length)

1. Calculate the probability that at least 2 out of the first 3 appointments are with female students

First, select the first 3 appointment slots and check for "F".

first_3_F = None
None
num_F = None
print(num_F)
F_2plus = None
print(F_2plus)
prob_F_2plus = None
print(prob_F_2plus)

2. Calculate the probability that after 4 appointment slots, all the female students have had an appointment

None

You noticed that coming up with the sample space was probably the most time-consuming part of the exercise, and it would really become unfeasible to write this down for say, 10 or, even worse, 20 appointments in a row. You'll learn about methods that make this easy in the next lecture!

Sources

https://www.datacamp.com/community/tutorials/statistics-python-tutorial-probability-1

https://www.youtube.com/watch?v=oYXYLljkC48&index=2&list=PLcmJYc2muOR9H96hGlUBV2DkviVZFmHAh

ds-prob-via-outcomes-lab's People

Contributors

fpolchow avatar loredirick avatar mike-kane avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.