Now that we've gathered our data, let's talk about what we're actually going to do in the upcoming lessons. 1
Let's talk about the theory behind the machine learning model that we're gonna use. The machine learning 2
model that I wanna introduce to you in this module is called the Naive Bayes Classifier" 3
and the beauty of this model is its simplicity and its speed. Given that we're looking to classify spam 4
email, speed is actually a really, really nice attribute to have because nobody really wants to wait for 5
ages for some sort of complex neural network to run just to receive an email. 6
The speed of the Naive Bayes Model in fact made it one of the most popular machine learning models in 7
spam classification and is even heavily used today. 8
Spam classification along with weather forecasting is in fact one of the classic applications of the 9
Naive Bayes machine learning model. 10
Now, as I said, the model's speed comes through its simplicity and the simplicity of this machine learning 11
model will also allow us to build this thing from the ground up in a relatively short amount of time. 12
There's going to be zero magic on how this thing works. 13
Instead of calling a built-in function in scikit-learn, you're actually going to see all the nuts and 14
bolts that go into this machine learning model, because you're gonna be coding it up in Python yourself. 15
But so much for the sales pitch on Naive Bayes. 16
Let's talk a little bit about how the Naive Bayes Classifier actually works because this will help us 17
plan out our Python code that we're going to write and also put the upcoming coding lessons into context. 18
Now to make a decision if an email is spam or not spam what the Naive Bayes Classifier does is it will 19
compare two probabilities, and by probability I just mean the chances of something, the likelihood of an 20
event. 21
What our algorithm will do is it will calculate the probability of an email being spam and it will also 22
calculate the probability of an email not being spam, of being legitimate. 23
Now if the probability of an email being spam is higher, then the email will be classified as spam. That's 24
all it is. Our algorithm will basically look at two numbers and then classify an email based on which 25
number's higher. 26
This is what it boils down to behind the scenes. 27
Now one of the things that I find really helpful in thinking about this kind of stuff is to look at 28
these decisions that our algorithm is making visually. 29
So let me illustrate what this would look like in a picture. 30
Suppose we have a chart with an X and a Y axis. On the horizontal, 31
we've got the probability of an email not being spam. 32
And on the vertical we have the probability of an email being spam. In the middle of this chart, 33
we can draw a line. This line is where the X equals the Y. 34
This is where the two probabilities are equal. 35
Now in our Naive Bayes model this line in fact has a very special name, 36
this line is called the decision boundary. The model will decide if an email is spam or not spam based 37
on which side of this line an email falls on. Suppose an e-mail comes in. The probability of this e-mail 38
being spam is calculated to be 70 percent. 39
Where would it go on the chart? Right here. 40
It would go far above this dividing line. 41
And, guess what? 42
Because the email is above the decision boundary, 43
the algorithm will classify this email as spam. 44
Makes sense, right? Now, 45
what if the e-mail comes in and it's only got a 40 percent chance of being spam? 46
It would go somewhere around here. 47
Since this email is below the decision boundary, it would be classified as legitimate, not spam, and we 48
can plot every single email on this chart. So this classification step is actually the final step that 49
the algorithm takes. 50
It applies a decision rule based on the probabilities of the email being spam or not being spam. 51
But what we haven't really talked about so far is where these probabilities actually come from. 52
And this is what we're going to cover in the next lesson. 53
I'll see you there.