oldoc63 / learningDS

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

Calculating Probabilities using Python #423

Open oldoc63 opened 2 years ago

oldoc63 commented 2 years 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 2 years 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 2 years 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 2 years 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.