Python Tutorial: Probability distributions

Learn four probability distributions that show up in technical interviews: Bernoulli for coin flips, Binomial for multiple trials, Normal for the bell curve, and Poisson for event counts over time. Each one gets its parameters, use cases, and code examples using SciPy and Matplotlib.
Chapters
Lets discuss probability distributions. We'll review what a probability distribution is, exactly why it's important, and then hone in on the four distributions that are most common in interviews. Probability distributions are fundamental to statistics, similar to the way that data structures are to computer science. Simply put, they describe the likelihood of an outcome. The probabilities must all add up to one and can be discrete like the roll of a die, or continuous like the amount of rainfall. Here we see an example of a continuous probability distribution where the total area under the curve adds up to one. There are hundreds of distributions out there, but only a handful actually turn up in practice. In this course, we'll address only the most likely to be brought up in your next interview. These include binomial, Bernoulli, normal and Poisson. We'll use the RVS command in SCIPY to simulate all of these distributions. Before you visualize them using matplotlib, let's talk a bit more about each one. First up is Bernoulli, a discrete distribution that models the probability of two outcomes. Here we see the results of a coin flip, a common Bernoulli example. Both heads and tails have the same probability of 0.5, so the values are even in this sample. Since there are only two possible outcomes of Bernoulli, the probability of one is always one minus the probability of the other. Next up is the binomial distribution, which can be thought of as the sum of the outcomes of multiple Bernoulli trials, meaning those that have an established success and failure. It's used to model the number of successful outcomes in trials where there is some consistent probability of success. These parameters are often referred to as K the number of successes, N the number of trials and P the probability of success. You can input these parameters into the CDF and PMF functions in Python. Here we see the results of a sample representing the number of heads in two consecutive coin flips using using a fair coin taking the form of a binomial distribution. We talked a little about normal distribution when we worked through Central Limit Theorem, but it's well worth its own slide here. The normal distribution is a bell curve shaped continuous probability distribution that is fundamental to many statistics concepts like sampling and hypothesis testing. Here we see the normal distribution with the numbers overlaid that serve as a reminder of the 68, 95 99.7 rule which states that approximately 68% of observations fall within one standard deviation of the mean, 95% of observations within two standard deviations and 99.7% within three deviations. It's good to have this memorized. Like the binomial distribution, the Poisson distribution represents a count or the number of times something happened. It's calculated not by a probability p and a number of trials N, but by an average rate shown by lambda. Here we can see a few Poisson curves given different values of lambda. As the rate of events changes, the distribution changes as well. Poisson is the way to go for counting events over time, given some continuous rate. In this example, you're given a time interval and a rate. What's the probability that you see at least one shooting star in an hour? To summarize, we touched on what probability distributions are, went over common distribution types, and then dove into a few notable distributions more in depth. Now let's work through some exercises.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







