Code

Probability Theory: Basic Concepts, Formulas, and Examples of Problem Solving

Probability Theory: Basic Concepts, Formulas, and Example Problem Solving

Contents:

Today we will talk about probability theory - a branch of mathematics that is widely used in machine learning, game development, statistics, and data science.

Course with employment: “Profession Data Analyst"

Learn more

What is probability theory

Probability theory is a science that studies the world of chance and tries to predict it. It involves concepts such as "events" and "probabilities," which have their own properties and operations—we'll talk about them a little later.
The easiest way to demonstrate how probability theory works is with the example of flipping a coin. In this case, we have two options: heads or tails, which means the chance of each side coming up is the same and is 50%.

You can try your luck on Google by searching for "coin toss." Image: Google

But how can I be sure that this is really true? For example, I can flip a coin ten times, and magically it will come up heads nine times in a row and tails once. Does this mean that the chance of getting heads is 90%? Of course not – and there is a scientific explanation for this.
The fact is that probability theory considers random events within the framework of infinity. In other words, if we toss a coin an infinite number of times, the chances of getting heads or tails will approach 50%.
In mathematics, this pattern is called the law of large numbers, and this law is one of the fundamental ones for data science. The trick is that the more data we have on hand, the more accurate our predictions can be.
The same logic works for other random phenomena—for example, the chance of rolling a 5 on a die is 1 in 6, and the probability of lightning striking the same place twice is about 1 in 500.

What do you think the odds are that all 15 dice will roll the same result? About 0.000000000002%, or two chances in a trillion. Image: Google

Probability theory helps us predict the chance of events occurring when the answer is not so clear-cut and many factors influence them.

Basic Concepts

We've mentioned the words "event" and "probability," but we haven't explained what they actually mean in the context of probability theory. Let's figure it out.

Event

An eventis anything that can happen when we perform some action. For example, if we toss a coin, the event is whether it lands on heads or tails. Capital letters of the Latin alphabet are used to denote events. For example, for heads we can choose the letter A, and for tails - B.
There are many different types and classifications of events, but in this article we will focus on the main four:

  • Certain— those that will definitely happen. If you throw a glass on the floor, there is 100% probability that it will fall down.
  • Impossible— those that will never happen. If you throw the same glass on the floor, it will never fly up (moral of the story: don't throw glasses on the floor, unless you're on the ISS).
  • Random— those that may or may not happen. For example, if we roll a dice, we can't say with certainty that the number 2 will come up.
  • Incompatible— those that exclude each other. For example, when you toss a coin, either heads or tails can come up; they can't come up both at the same time.
Becoming an expert in probability theory is very simple - you just need to get a cat and observe it. Infographics: Olya Ezhak for Skillbox Media

If you collect all incompatible events together, they are called a complete group of events. This is a set of events, one of which is sure to happen if we perform an action, while others will never happen. For example, when we roll a dice, only one side can come up.

Probability

Probabilityis a number that represents the chance of an event occurring. For example, the chance of winning the lottery might be 1 in 1,000,000.
We've written probabilities as percentages and ratios, but mathematicians find it more convenient to arrange them in a range from 0 to 1. If the probability is 0, the event will never happen, and if it is 1, it definitely will. Anything in between is random.
The simplest way to calculate probability is to divide the number of favorable events by the total number of possible events. For example, if there are 36 cards in the deck and we want to get the king of spades, then the probability of this event is 1/36, or 0.03. If any of the kings were acceptable, the probability would be 4/36, or 0.1.

The initial probability that you will stumble upon a mine at the very beginning of a game of Minesweeper is about 20%. With each open cell, this chance increases. But this is if you rely only on luck.

We'll return to the formulas later, but for now, note that probability is not always an exact prediction, but only an estimate of the chance of an event occurring. As follows from the law of large numbers, if the chance of getting heads and tails is 50%, this does not mean that they will come up alternately.
Probability can also be conditional - or depend on another event. For example, if we want to draw any ace from a deck of cards, the chance is 4/36. But if someone has already drawn an ace before, the probability will be 3/35. This is because there is one less card in the deck and the number of favorable events has also decreased.
We're done with the definitions - now let's find out how events can be controlled.

What is Event Algebra?

When we calculate probabilities, we may be satisfied with more than one outcome of events. Or another situation - it may be important for us that two events occur together. In such cases, event algebra comes to the rescue. Let's figure out what actions it allows you to perform.
Disclaimer: in this section, we will not consider subtraction and addition of events, because they are quite complex for a first acquaintance with probability theory. We may publish a separate article about them soon.

The Sum of Events

The sum of two events A + B is a compound event that will occur if either event A or event B, or both, occur.
Let's say we want to calculate the probability of a die ending in a 2 or a 4. Let's denote the event of "ending in a 2" as A, and the event of "ending in a 4" as B. Since the die has only six sides, the probability of ending in each of these sides is 1/6.
And since we are interested in either event A or event B, we look for the sum of these events, A + B. We calculate the corresponding probabilities:

Image: Skillbox Media

It turns out that the chance of getting a 2 or 4 when rolling a dice is 2 to 6, or 1 to 3, or 33%.
The addition rule can be applied not only to two events, but to any number of them. For example, event A + B + C + D will occur if at least one of events A, B, C, D, or one of their combinations, such as A and C or A, C, and D, occurs.

Product of Events

The product of events A and B is the event A × B, which will occur if both event A and event B occur.
Let's say we toss a coin twice and want to know what the chance of it coming up tails both times. Let us remember that the probability of landing on heads is 1/2.
Let us designate the events: A - heads landing for the first time, B - heads landing for the second time. We calculate the probabilities:

Image: Skillbox Media

We get that the chance of getting heads twice in a row is 25%.
As with the sum, the product of events can be calculated for any number of different events. Let's continue the coin example—now we want it to land four times in a row.
We add two new notations: C—tails lands for the third time, D—tails lands for the fourth time. The probabilities are the same; we calculate their product:

Image: Skillbox Media

Answer: The chance of getting heads four times in a row is 1 in 16, or 6.25%.

Sum of Compatible Events

When we talked about adding probabilities, we used incompatible events because only one side (or edge, if you're really lucky) can come up when rolling a die.
Now that we've covered the intricacies of probability multiplication, we can figure out how to add compatible events. In this case, simply subtract the product of two events from their sum. The formula looks like this:
P (A + B) = P (A) + P (B) – P (A ⋅ B)
An example of such addition can be the selection of random numbers. Let's say we have a set of numbers from 1 to 10 and we want to find the probability that the selected number will be either odd or divisible by 7 without a remainder.
We calculate the probabilities:

  • Event A is an odd number. The probability of choosing it is 5/10.
  • Event B - the number is divisible by 7 without a remainder. The probability is 1/10.

Since the number 7 satisfies both conditions, we are dealing with compatible events - that is, they can occur simultaneously. We use the formula: first, we find the sum of the probabilities, and then subtract the probability of intersection from it. Attention to the screen:

Image: Skillbox Media

Voila! It turns out that the chance of one of the two events occurring is 11/20, or 55%.
This concludes the algebra of events and moves on to more classical formulas. But don't worry, we'll explain everything in detail.

A few more formulas from probability theory

First, a universal formula. It looks like this:

Image: Skillbox Media

Let's figure out what all these mean Letters:

  • Function P calculates the probability that an event that suits us (A) will occur;
  • m denotes the total number of possible events;
  • n is the number of favorable outcomes.

For example, let's try to calculate the probability of landing tails using this formula:

Image: Skillbox Media

Everything is fine, the formula works.
Let's make the problem more difficult: let's calculate the probability of the coin coming up heads three times. To do this, you need to break the event down into several unique ones—for example, landing on heads on the first, second, and third tosses. Let's label these events as B, C, and D.

Image: Skillbox Media

Since these events are dependent on each other, friend, we need to multiply them - to do this, we substitute numbers into our formula:

Image: Skillbox Media

That's right - probability You calculated it correctly.
Several conclusions can be drawn from this formula:

  • If the probability is one, it is certain. The point is that all of the events out of a total number of possible events are suitable for us, meaning the event will definitely happen.
  • If the probability is zero, it is impossible. This is because none of the available events are suitable for us.
  • If the probability is between zero and one, it is random. This means that the total number of results is greater than zero, but not all of them are suitable for us.

Now you know enough to solve simple problems in probability theory, which we will do in the next section.

Solving problems in probability theory

When solving problems, use the main formula of probability theory, as well as the formulas for addition and product of the probability of events.

Problem 1. There are 52 cards in a deck. We decided to draw one from it - find the probability that it will be an ace.

Solution:
The layout is as follows:

  • The number of all possible events is 52, since there are 52 cards in the deck.
  • The number of favorable events is four, since there are only four aces in the deck.

Let's calculate the probability that of all the cards we will get an ace:

Image: Skillbox Media

Now let's calculate the sum favorable events:

Image: Skillbox Media

Answer: 4/52, or 1/13.

Problem 2. There are six coins in your pocket: two one-ruble coins, two five-ruble coins, and two ten-ruble coins. We take out two of them at random. Find the probability that they will both be of the same denomination.

Solution:
First, we take out the first coin. It could be a ruble, or five, or ten. It turns out that the probability of getting a coin of any denomination is 1/3.
Now we take out the second coin - it should be of the same denomination as the first. Since only one of them meets our criteria, the probability of this is 1/5. And since our events are related to each other, we multiply the probabilities of both:

Image: Skillbox Media

Answer: 1/15.

Problem 3. You roll a six-sided dice. Find the probability that the sum of the points rolled is 7.

Solution:
There are six different combinations that give the sum 7:

  • 1 — 6;
  • 2 — 5;
  • 3 — 4;
  • 4 — 3;
  • 5 — 2;
  • 6 — 1.

The total number of possible outcomes when throwing two dice is 6 × 6 = 36. We substitute our values ​​​​into the formula:

Image: Skillbox Media

Answer: 6/36, or 1/6.