First proposed by Thomas Bayes, Bayes' Theorem is one of the fundamental theorems in the realm of AI and Bayesian statistics. It can be utilized as a probability tool to effectively find conditional probability. Therefore, it has numerous real-life applications like drug testing, robotics, and machine learning.
Before we dive into the specifics of how Bayes' Theorem can be used in AI, let's first understand what conditional probability actually is.
Formally put, conditional probability is the probability of an event X occurring provided that an event Y has occurred.
We can simply understand it as the chance of something happening if we know that another event has taken place.
Bayes' Theorem is the name of the formula put forth for calculating conditional probability.
It is given by the following mathematical expression:
The above formula states that the conditional probability of event
Probability of event
Probability of event
This can then be divided by the probability of event
Bayes' theorem allows us to show how likely something is to occur through the values of already known occurrences of other events.
Since Python is a widely used language in AI, we can use the following code to set up a simple function that applies Bayes' Theorem.
pOfA = 0.5;pOfB = 0.7;pOfBGivenA = 0.82;def bayes(BGivenA, probabilityOfA, probabilityOfB):AGivenB = probabilityOfA * BGivenA / probabilityOfB;return AGivenB;pOfAGivenB = bayes(pOfBGivenA, pOfA, pOfB);print(pOfAGivenB);
Lines 3–5: Suppose we have some known values such as the probability of events A i.e. pOfA
, B i.e. pOfB
, and B given that A i.e pOfBGivenA
.
Lines 7–9: We can calculate the probability of A
happening when we know that B
has happened by applying Bayes' Theorem through the formula AGivenB = probabilityOfA * BGivenA / probabilityOfB
, which is defined in the function bayes
. This function simply returns AGivenB
.
Line 11: bayes
is called to save the value of pOfAGivenB
, which is then printed out to us.
Let's take System
We can apply Bayes' theorem to calculate
Since we don’t have P(Positive Test), we’ll have to calculate it using the rest of the values. For this, we need to consider the probabilities of getting a positive test result in both malfunction and non-malfunction cases.
Plugging in the values in Bayes’ theorem gives us our result:
Note: 0.142857 can now be expressed as a percentage. Hence, we can say that the probability of System
having a malfunction given a positive test result is 14.29%.
Bayes' Theorem can be put to effective use in numerous fields such as computing, health, and finance.
Let's take a look at three applications of Bayes' Theorem:
This technique is mainly used for optimizing black box functions. Simply put, this requires changing the parameters of the function until an optimal solution is achieved based on previously observed function evaluations.
Bayes' Theorem can be used to model decision-making problems in AI by calculating the probability of different outcomes based on available evidence. We can use it to further update the probabilities in the network as new evidence is obtained, leading to more informed decision-making.
Mostly used in machine learning, we apply Bayes' Theorem here for tasks such as text classification and spam filtering. For instance, the probability of an email being spam can be predicted by relating it to various keywords used in that email.
Since we can find an event's conditional probability through Bayes' Theorem, we can use it to predict various events in artificial intelligence or machine learning. We can further lead our calculations to higher precision by adding new observations in our data.
Test your knowledge of Bayes’ Theorem!
What does conditional probability help us understand?
How likely is the event A to occur?
How likely is the event A to occur if event B might take place?
How likely is the event A to occur if the event B has previously occured?
Free Resources