Probability is the foundation and language needed for most statistics. Probability deals with uncertainty in the real world. In Machine Learning and Data Science whatever the result we conclude is also uncertain in nature and the best way to interpret those results is to apply knowledge of probability. Come along and test yourself on the top 27 Probability Interview Questions (all solved and answered) before your next Machine Learning or Data Science interview.
A Probability Distribution is a statistical function that describes all the possible values and likelihood that a random variable can take within a given range.
There are two main types of probability distribution:
A or B wins the election?In a presidential election, there are four candidates. Call them A, B, C, and D. Based on our polling analysis, we estimate that A has a 20% chance of winning the election, while B has a 40% chance of winning. What is the probability that A or B wins the election?
We first notice the events that A wins, B wins, C wins, and D wins are mutually exclusive events since more than one of them cannot occur at the same time. For example, if A wins, then B cannot win. We know that the probability of the union of two disjoint events is the summation of individual probabilities. Therefore,
Let's suppose I roll a fair die. Let A be the event that an outcome is an odd number and let B be the event that the outcome is less than or equal to 3. What is the probability P(A|B)?
Given A = {1.3,5} and B = {1,2,3}, if we know B has occurred, the outcome must be among {1,2,3}. For A to also happen the outcome must be in A ∩ B = {1,3}. Since all die rolls are equally likely, then we calculate the conditional probability as:
A Combination is the choice of r elements from a set of n elements without replacement and where order does not matter. Is most used to group data. For example, picking three team members from a group, picking two colors from a color brochure, etc. It is mathematically defined as:
A Permutation is the choice of r elements from a set of n elements without replacement and where the order matters. Is used to list data, for example picking first, second and third place winners, picking two favorite colors -in order- from a color brochure, etc. It is mathematically defined as:
The Bernoulli distribution is the discrete probability distribution of a random variable which takes a binary output: 1 with probability p, and 0 with probability (1-p). The idea is that, whenever we are running an experiment that might lead either to success or to a failure, we can associate with our success (labeled with 1) a probability p, while our failure (labeled with 0) will have probability (1-p).
In the Binomial distribution we keep the same idea as before: we count probability of a success or failure outcome in an experiment, but this time is is repeated multiple times.
Probability mass functions are used to describe discrete probability distributions and allow us to determine the probability of an observation being exactly equal to a target value.
Density functions are used to describe continuous probability distributions and allows us to determine the probability of an observation being within a range around our target value by computing the area under the curve for our interval.
1000 times, and 550 times it showed up heads. Do you think the coin is biased?To answer this question let's say is the number of heads and let's assume that the coin is not biased. Since each individual flip is a Bernoulli random variable, we can assume it has a probability of showing up heads as p = 0.5, so this will lead to the following expected number of heads:
And the following standard deviation:
Given that we got a 1000 sample size, we can apply the Central Limit Theorem to approximate the total number of heads as normal distribution and calculate the corresponding z-score to test the hypothesis that the coin is fair.
This means that, if the coin were fair, the event of seeing 550 heads should occur with a < 1% chance under normality assumptions. Therefore, the coin is likely biased.
Let's say:
Can you find the probability of dangerous Fire when there is Smoke?
We can then discover the probability of dangerous Fire when there is Smoke using the Bayes' Theorem:
P(Fire | Smoke) = P(Fire) * P(Smoke | Fire) / P(Smoke)
= 0.01 * 0.9 / 0.1
= 0.09 (9%)So probability of dangerous fire when there is a smoke is 9%.
There is a fair coin (one side heads, one side tails) and an unfair coin (both sides tails). You pick one at random, flip it five times, and observe that it comes up as tails all five times. What is the chance that you are flipping the unfair coin?
Let the event of flipping the fair coin be denoted by F , the event of flipping the unfair coin be denoted by U and the event of tossing all 5 tails by T. We are required to find P(U|T) and we can use the Bayes' theorem as:
where we use the law of total probability to compute P(T) as:
Now, we know that:
P(T|U) = 1 is the probability of the unfair coin flipping tails in a particular toss.P(U) = P(F) = 0.5 since we pick the unfair and the fair coin at random. P(T|F) is the probability of the fair coin flipping five tails:
Now, by putting all these values on the Bayes' rule formula we got:
Therefore the probability we picked the unfair coin is about 97%.
8?What is the probability that two dices sum to 8 when the first dice is 6?
Given the probability formula:
where is the number of desired outcomes and is the number of possible outcomes. For one single fair dice, we have 6 possible outcomes, so for two fair dices, we have 6*6 = 36 possible outcomes.
We want that the two dices sums 8 so the possible combinations are:
(2,6),(3,5),(4,4)(5,3),(6,2)
We got that the number of desired outcomes are 5. The probability is then
For the second part we use the Bayes Theorem and conditional probability formula:
Let's say:
A is the event of getting an 8B is the event of getting a 3.Now, from the previous combination, we got that (3,5) is the only event that satisfies both A and B so then P(A ∩ B) = 1/36. On other hand, the probability of getting a 3 in a fair dice is just 1/6, we now put these values on the previous formula and compute:
To transform a Skewed Distribution into a Normal Distribution we apply some linearized function on it. Some common functions that achieve this goal are:
Square root transformation: this one has an average effect on distribution shape: it’s weaker than logarithmic transformation, and it’s also used for reducing right-skewed distributions, but is defined only for positive numbers.
Reciprocal transformation: this one reverses the order among values of the same sign, so large values become smaller, but the negative reciprocal preserves the order among values of the same sign. The only condition is that this function is not defined for zero values.
Exponential or Power transformation: has a reasonable effect on distribution shape; generally, we apply power transformation (power of two usually) to reduce left skewness. We could also try any exponent to see which one provides better results.
Box-Cox Transformation: in this transformation, we’re searching and evaluating all the other transformations and choosing the best one. It's defined as:
The exponent here is a variable called lambda (λ) that varies over the range of -5 to 5, and in the process of searching, we examine all values of λ. Finally, we choose the optimal value (resulting in the best approximation to a normal distribution) for the variable.
Bayes' Rule is an equation that allows us to calculate a conditional probability with new information we already have. Given two different events A and B, we can think in Baye's theorem in terms of two events:
So in this way A is the event we want the probability of. Using the Bayes' theorem the problem can be set as:
where:
Now, to test between two hypotheses we compute the probability of each one using the previous formula and compare them. The hypothesis with the higher posterior probability is accepted.
50% of all people who receive a first interview receive a second interview; 95% of your friends that got a second interview felt they had a good first interview; 75% of your friends that DID NOT get a second interview felt they had a good first interview. If you feel that you had a good first interview, what is the probability you will receive a second interview?
Supposing that my friends are a good representation of the entire population, the key to solving problems like this is to define the events carefully. Let's denote:
pass: being invited to a second interview,fail: not being so invited,good: feel good about the first interview, andbad: don't feel good about the first interview.So according to the problem, we need to find given that:
Let's use the Bayes theorem such as:
where is given by:
Thus
So feeling good about the interview only makes me slightly more likely to actually move on.
There are two main types of probability distributions: discrete and continuous.
Discrete distributions
1 with probability p and value 0 with probability q = 1 − p, can be thought of as a model for the set of possible outcomes of any single experiment that asks a yes-no question.Continuous distributions:
Three ants are sitting at the corners of an equilateral triangle. Each ant randomly picks a direction and starts moving along the edge of the triangle. What is the probability that none of the ants collide?
Each ant has two possible ways to go: the edge on its left L and the edge on its right R. Now the only way no ant will collide is if they all walk in the same direction along the triangle (assuming they all move at the same speed). Overall the ways how the ants can move are:
We have a total of 8 ways how the 3 Ants can move, out of these, only RRR and LLL are the ways by which the Ants will never meet. So the probability of it is 2/8 = 0.25
A test has a true positive rate of 100% and a false positive rate of 5%. There is a population with a 1/1000 rate of having the condition the test identifies. Considering a positive test, what is the probability of having that condition?
Let's denoted as A a person who has the disease, and let B a positive test. To calculate P(A|B) and we will use the Bayes' theorem:
Where P(B) is given by the law of total probability:
Now, we know that:
1000 people, 1 person who has the disease will get true positive result, so P(A) = 0.001 and P(notA) = 1 - P(A) = 0.999.100%, so P(B|A) = 15%, so P(B|notA) = 0.05.Therefore,
Thus, there is only a 2% probability of one person having the disease even if the reports say that it has the disease.
The Bayesian approach defines probability as the measure of believability one has about how a particular event occurs. It uses the Bayes theorem to help us update beliefs about random events once we've seen new evidence about the event, so we use Bayesian statistics to create different beliefs after new evidence is uncovered. It differs from frequentist statistics that rely only on data from repeated trials.
The Binomial distribution describes the probability of obtaining k successes in n Bernoulli experiments, i.e an experiment which has only two possible outcomes, often call them success and failure. Its probability function describes the probability of getting exactly k successes in n independent Bernoulli trials:
The Geometric distribution describes the probability of experiencing a certain amount of failures before experiencing the first success in a series of Bernoulli experiments. This probability is given by:
So as we can see, the key difference is that in a binomial distribution, there is a fixed number of trials meanwhile in a geometric distribution, we’re interested in the number of trials required until we obtain a success.
The Cumulative Distribution Function (CDF) can be defined for any kind of random variable, i.e. discrete or continuous, and it tells us the probability that the random variable X takes a value less than or equal to a particular value x:
The CDF is used to determine the probability that an observation will be greater than a certain value, or between two values.
A Probability Density Function (PDF) can be defined only for continuos random variables and it tells us the probability of the random variable X falling within a range of values (a, b) by computing the integral of this variable's PDF over that range:
As we can see from the previous definition, the PDF is used when we want to know the probability that an observation relies on a certain range, with the restriction that the observation comes from a continuous random variable.
Disjoint events are events that never occur at the same time. These are also known as mutually exclusive events. These are often visually represented by a Venn diagram, such as the below. In this diagram, there is no overlap between event A and event B, so these two events never occur together.
Independent events are unrelated events, i.e. an event A does not give any information about B and the outcome of one event does not impact the outcome of the other event. Independent events can, and do often, occur together.
Provide an example of how is used.
The likelihood and posterior probability are two quantities that are defined and used in the Bayes Theorem:
in which:
An example case of use can be trying to find the probability that a given person has cancer. For that, we would initially just say it is whatever percent of the population has cancer. However, given additional evidence such as the fact that the person is a smoker, we can set the likelihood as the probability of being a smoker given that the person has cancer, and set as the posterior the probability of having cancer given that the person is a smoker.
Thus, given additional evidence such as the fact that the person is a smoker, we can update our probability, since the probability of having cancer is higher given that the person is a smoker. This allows us to utilize prior knowledge to improve our probability estimations.
An event can only be independent of itself when either there is no chance of it happening or when it is certain to happen. To demonstrate this, let's remember that two events A and B are independents if:
Now if B = A, then
and this result only can occur when P(X) = 1 or P (X) = 0 i.e. when:
100% sure that it will happen.Prepare for Claude interview questions with answers for AI engineers covering the Anthropic API, Messages API, prompting, tool use, structured outputs, prompt caching, adaptive thinking, MCP, security, and production agents....
Prepare for prompt engineering interviews with answered LLM prompting, ChatGPT prompting, and Claude prompting interview questions covering context windows, few-shot learning, structured outputs, tool use, prompt caching, hallucination reduction, eva...
Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....