oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Calculating Probabilities using Python #423

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

The binom.pmf() method from the scipy.stats library can be used to calculate the PMF of the binomial distribution at any value. This method takes 3 values:

For example, suppose we flip a fair coin 10 times and count the number of heads. We can use the binom.pmf() function to calculate the probability of observing 6 heads as follows:

oldoc63 commented 1 year ago

Notice that two of the three values that go into the stats.binomial.pmf() method are the parameters that define the binomial distribution: n represents the number of trials and p represents the probability of success.

oldoc63 commented 1 year ago

Change the scaffolded code to calculate the probability of observing 3 heads in 10 fair coin flips. Save this probability to prob_1.

oldoc63 commented 1 year ago

Using the same logic, calculate prob_2 to be the probability of observing 7 heads out of 20 fair coin flips. However, this time, directly input values into the stats.binomial.pmf() method. Then print prob_2.