Sitemap

Learn statistics with Python: Probability

7 min readAug 6, 2025

--

Probability is a fundamental concept in mathematics and statistics that measures the likelihood of an event occurring. It provides a way to quantify uncertainty and make informed decisions based on the available information. Probability theory is the foundation of many statistical methods and plays a crucial role in various fields, including finance, science, engineering, and social sciences.

Key Concepts in Probability

1. Experiment, Outcome, and Event:

- Experiment: A procedure that yields one of a possible set of outcomes. For example, rolling a die is an experiment.

- Outcome: A possible result of an experiment. For example, getting a 4 when rolling a die is an outcome.

- Event: An event is one or more outcomes of an experiment. It is a subset of sample space (s). For example, getting an even number when rolling a die is an event.

2. Probability of an Event:

- The probability of an event is a measure of the likelihood that the event will occur. It is denoted by (P(E)), where (E) is the event. The probability of an event ranges from 0 to 1, where 0 indicates that the event will not occur, and 1 indicates that the event will certainly occur.

3. Sample Space:

- The sample space is the set of all possible outcomes of an experiment. It is denoted by (S). For example, the sample space of rolling a six-sided die is (S = {1, 2, 3, 4, 5, 6}).

4. Classical Probability:

  • Classical probability is defined as the ratio of the number of favourable outcomes to the total number of possible outcomes. It is given by the formula:

Question: You are rolling a standard six-sided die. What is the probability of rolling a number greater than 4?

Answer: Identify the sample space as being S = {1, 2, 3, 4, 5, 6}. The favourable outcomes are 5 and 6. The total favourable outcomes are 2 and the total possible outcomes are 6. Using the classical probability formula, the probability is 2/6 or 1/3, which is 0.33333.

5. Empirical Probability:

  • Empirical probability is based on observed data. It is calculated by dividing the number of times an event occurs by the total number of trials. It is given by the formula:
Press enter or click to view image in full size

Question: A quality control inspector at a factory checks a random sample of 100 light bulbs for defects. Out of the 100 light bulbs, the inspector finds 7 defective bulbs. Based on this sample, what is the empirical probability that a light bulb produced by the factory is defective?

Answer: The total number of trials is 100 and the total number of defective bulbs is 7. Using the empirical probability formula, the probability is 7/100 or 0.07.

6. Conditional Probability:

  • Conditional probability is the probability of an event occurring given that another event has already occurred. It is denoted by (P(A|B)) and is calculated using the formula:

where (P(A | B) is the probability of both events A and B occurring.

7. Independent and Dependent Events:

  • Independent Events: Two events are independent if the occurrence of one event does not affect the occurrence of the other event.

Question: A fair coin is flipped twice. What is the probability of getting heads on both flips?

Answer: The probability of getting heads in a single flip is ½. The probability of getting a head in both flips is ½ x ½, being ¼ or 0.25.

  • Dependent Events: Two events are dependent if the occurrence of one event affects the occurrence of the other event.

Question: A box contains 5 red balls and 3 blue balls. You draw two balls from the box one after the other without replacement. What is the probability that both balls drawn are red?

Solution: The total number of balls in the box is 8 (5 red and 3 blue). The probability of drawing the first red ball is 5/8. After drawing the first red ball, there are 7 balls in the box (4 red and 3 blue).The probability of drawing the second red ball is 4/7. The combined probability is:-

Press enter or click to view image in full size

See video on probability:- https://youtu.be/CNrKwF8nUr4

Practice questions

Practice Question 1: Probability of an Event

A deck of standard playing cards has 52 cards, consisting of 4 suits (hearts, diamonds, clubs, spades) with 13 cards each. What is the probability of drawing an Ace or a King from a well-shuffled deck?

Press enter or click to view image in full size

See video on ace or kings:- https://youtu.be/em-HxfV5L48

Practice Question 2: Probability of Intersection

In a classroom, there are 12 boys and 8 girls. If a student is selected at random, what is the probability that the student is a boy or has a name starting with the letter “A,” given that 3 boys and 2 girls have names starting with “A”?

Press enter or click to view image in full size

See video on students:- https://youtu.be/q6SyJTVx-6g

Practice Question 3: Conditional Probability

A bag contains 4 red, 5 green, and 3 blue marbles. A marble is drawn at random from the bag. If the drawn marble is green, what is the probability that another marble drawn without replacement is also green?

Press enter or click to view image in full size

See the video on marbles:- https://youtu.be/_Y6zmsBxfVk

Practice Question 4: Probability of Complement

The probability of raining on a particular day is 0.3. What is the probability that it will not rain on that day?

Press enter or click to view image in full size

See video on rain:- https://youtu.be/bl2TlTjeYEQ

Practice Question 5: Probability with Dice

Two six-sided dice are rolled. What is the probability that the sum of the numbers on the dice is 7?

Press enter or click to view image in full size

See the video on dice:- https://youtu.be/9P5uFFRbWT4

Types of Probability

1. Theoretical Probability:

  • Theoretical probability is based on the assumption of equally likely outcomes. It is calculated using the classical probability formula. For example, the theoretical probability of rolling a 3 on a six-sided die is (P(3) = 1/6).
Press enter or click to view image in full size

See video on theoretical probability:- https://youtu.be/msazN3HnWEM

2. Experimental Probability:

  • Experimental probability, also known as empirical probability, is based on actual experiments and observations. It is calculated using the empirical probability formula. For example, if a die is rolled 100 times and 3 appears 15 times, the experimental probability of rolling a 3 is (P(3) = 15/100 = 0.15).
Press enter or click to view image in full size

See video on empirical probability:- https://youtu.be/-oXm2HsLHqk

3. Subjective Probability:

- Subjective probability is based on personal judgment, intuition, or experience rather than on objective calculations. For example, a weather forecaster might estimate a 70% chance of rain based on their experience and analysis of weather patterns.

Subjective probability is based on personal judgment, intuition, or experience, rather than on objective data or calculations. Because subjective probability is inherently personal and may not be grounded in empirical data, it is difficult to calculate it using mathematical formulas or Python code in the same way we calculate classical or empirical probabilities.

Question: Suppose you assign subjective probabilities to the outcomes of a weather forecast: Probability of sunny: 0.5; Probability of rainy: 0.3; Probability of cloudy: 0.2.

Press enter or click to view image in full size

See video on subjective probability:- https://youtu.be/ybMIRZtTyYE

Applications of Probability

Probability has numerous applications in various fields, to include:-

1. Finance: Probability is used in risk assessment, portfolio management, and options pricing. Financial analysts use probability models to predict stock prices, interest rates, and market trends.

2. Science and Engineering: Probability is used in designing experiments, analysing data, and making predictions. It plays a crucial role in fields such as physics, biology, and engineering.

3. Medicine: Probability is used in clinical trials to determine the effectiveness of treatments and to assess the likelihood of side effects. It is also used in epidemiology to study the spread of diseases.

4. Gaming and Gambling: Probability is used to calculate odds and expected outcomes in games of chance, such as lotteries, casinos, and sports betting.

5. Artificial Intelligence and Machine Learning: Probability is used in algorithms for classification, regression, and decision-making. Probabilistic models, such as Bayesian networks, are used to handle uncertainty and make predictions based on data.

Conclusion

Probability is a powerful mathematical tool that allows us to quantify uncertainty and make informed decisions based on data. By understanding the key concepts of probability and its different types, we can apply probabilistic reasoning to a wide range of real-world problems. Whether it’s predicting market trends, designing experiments, or assessing risks, probability provides the foundation for statistical analysis and decision-making.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.