Menu

Understanding Probability and Common Distributions

Understanding Probability and Common Distributions

Probability measures how likely an event is to occur. Its value ranges from 0 to 1, where 0 represents an impossible event and 1 represents a certain event.

For example, when a fair six-sided die is rolled, the probability of obtaining a 4 is (1/6), because one of the six equally likely outcomes is 4.

Basic Probability Calculations

The probability of an event is calculated as:

[
P(A)=\frac{\text{Number of favorable outcomes}}{\text{Total equally likely outcomes}}
]

Python can perform simple probability calculations directly.

favorable_outcomes = 1

total_outcomes = 6

probability = favorable_outcomes / total_outcomes

print("Probability of rolling a 4:", probability)

For more complex events, probability rules help determine the likelihood of combined outcomes.

For two independent events (A) and (B), the probability that both occur is:

[
P(A \cap B)=P(A)\times P(B)
]

For example, the probability of getting heads on two independent fair coin tosses is (1/2 \times 1/2 = 1/4).

The Binomial Distribution

The binomial distribution models the number of successes in a fixed number of independent trials, provided each trial has the same probability of success.

For example, it can model the number of customers who purchase a product when each customer's purchase decision is represented as a success or failure under these assumptions.

from scipy.stats import binom

n = 10

p = 0.3

probability = binom.pmf(4, n, p)

print("Probability of exactly 4 successes:", probability)

Here, n is the number of trials, p is the probability of success in each trial, and binom.pmf() calculates the probability of exactly four successes.

The Normal Distribution

The normal distribution is a continuous, bell-shaped distribution characterized by its mean and standard deviation. It appears in many statistical applications, although real-world data is not always normally distributed.

from scipy.stats import norm

mean = 100

standard_deviation = 15

probability = norm.cdf(115, loc=mean, scale=standard_deviation)

print("Probability of a value at or below 115:", probability)

The cumulative distribution function, norm.cdf(), calculates the probability of observing a value at or below the specified threshold under the assumed normal distribution.


Python for Data Science

VA

Vishalini A



Learn via Video Course

undefined Logo

NaN hrs



Get in Touch For Details