Okay. So firstly, let's talk about Supervised Learning. And supervised learning really is like having a teacher 1
there, having a trainer there, who's guiding you step by step, telling you, "That was right, that was wrong," 2
or "This is a flower. 3
This is a plant." 4
It's a sort of handholding way of teaching the computer what to do. 5
So one of the most famous examples of supervised learning is training in computer to recognize a cat, 6
right? 7
So we would say to the computer, "This is a cat. 8
This is a cat. 9
This is cat. 10
This is a cat and this is a cat." 11
And, of course, as humans, it's very easy for us to look at any image and identify, you know, whether it's 12
a cat or a dog, or any other sort of animal. 13
But, essentially, we kind of went through this training process when we were young as well, 14
right? 15
When we were babies and we looked at this strange fluffy animal, you know, maybe one of our parents said, 16
That is a cat," or maybe your teacher said, "That is a dog." 17
And over time, we learned pattern recognition. 18
We understood how to classify different animals based on repeated exposure. 19
And this is exactly what we do for machine vision. 20
So we feed the computer loads and loads of cat images. 21
And if there's one thing that the Internet is not short on, it's cat images. And every single time we 22
show it, this cat image, the cat image also has a label saying, "This is a cat." 23
So every single time the computer sees this particular blend of pixels, it'll be taught that that is 24
a cat. 25
So this is why it's supervised. The training data is always labeled. 26
So what we're hoping for is after this repeated exposure where the machine learns that this is the rough 27
outline of what a cat looks like, then the next time when we ask the computer and feed it a piece of 28
data that's unlabeled saying, "What is this?" The machine learning models should be able to identify that 29
it has a lot of features that are very similar to the previous images of cat and it should spit out 30
the answer: 31
"This is a cat," even though it looks like a burrito. 32
So when you're training that machine learning model, you're essentially presenting it with loads of images, 33
and each image comes with a label. 34
So the data is clearly labeled and gets fed into the machine learning model. 35
So this is a cat. 36
This is a dog and this is a cow. 37
Now, you're going to do this for lots of different types of cats, dogs, and cows, 38
so that you cover all the different breeds, and all the different sizes, or lighting conditions, et cetera. 39
And the machine learns through this experience and begins to classify these images into their respective 40
groups. 41
So, in this case, the model is the thing that does the learning and the data that you feed it is called 42
the training data. 43
Now, once you've completed your training, at a later stage, you should be able to present an image of a 44
dog and that the model has never ever seen before. 45
So this is not a part of the training data. And you ask the model, 'What is this?" based on all of your training. 46
"Can you classify what this image is?" And it should use what it's learned based on the training data 47
and be able to spit out an answer and say, "This is a dog." 48
So the new image that the model has never seen is called the testing data and the result that it spits 49
back out is the output. 50
Now, the output can be in various forms. 51
It could be a word or it could be a move on a chessboard. 52
It really depends on how you trained up the model and what you want it to do. 53
So this is one of the most fundamental types of supervised learning and it's known as classification. 54
So if you imagine, you're trying to teach a computer to differentiate between apples and pears. 55
Now, to us, as humans, this seems like a really simple task. But if you imagine trying to turn this task 56
into a programming exercise where you have to tell the computer what features it had to look for in 57
order to tell the difference between an apple and a pear, it's actually a really, really complex problem. 58
Because you could say, maybe, "Oh, computer, you know if you blur everything up and you look at all the pixels 59
in each image, the apple pictures tend to have more red colors than the pear pictures. 60
So from our experience, we know that pears tend to be more green and apples tend to be more red. 61
But if you designed a program the computer in this way, 62
what happens when you have a green apple, then the computer is probably going to think that's a pear, right? 63
Now, also, what if you have some sort of fruit that it's never ever seen before even though you can write 64
a lot of code and specify all of the unique features of apples when it's compared to a pear. 65
So, say, if you said apples tend to be more round than pears, apples tend to be a little bit redder than 66
pears, 67
and then you try and present the computer with something it's never ever seen before that is an anomaly 68
that doesn't belong in the apple or the pear camp, 69
then it's going to try and use those rules that you defined and try and classify it, and it'll probably 70
classify this as an apple. And through a lot of research, 71
it's been demonstrated that even though we're really, really good at pattern recognition as humans, we 72
can't always pinpoint exactly what it is that makes a certain thing that. I mean, 73
try and think of what makes an apple unique amongst all the other fruits or, indeed, any other item in 74
the world. 75
It's pretty difficult and time consuming to come up with a program with a list of rules that classifies 76
an apple and makes the computer differentiate it from a peach, for example. 77
But in the case of machine learning, you can feed that machine learning model a whole bunch of images 78
of cats, of dogs. of pears, of apples, of anything that you can imagine. 79
And as long as all of those pieces of data are labeled and you give the model enough instances of each 80
and every category, then it should be able to spit out what each of the items were, and be able to classify 81
them based on the features that it's identified. And the nice thing about a lot of these machine learning 82
models is that they're reusable. So you could probably create a generic classifier that looks at handwritten 83
numbers and is able to figure out what those numbers are. 84
So turning it from an image to an integer, for example. But you can use that same generic classifier, and 85
instead of training it on images of handwritten numbers, you could feed it emails that are labeled as 86
spam or not spam and it could classify new emails based on those criteria. 87
So once you've created a good model or a good generic classifier, if you change the training data, you 88
can get it to do different things without having to recode the entire model. 89
And this is one of the advantages of machine learning. 90
Now, let's look at how a machine might do this. 91
So, say, if we have a graph where we have a threshold for emails that should go into the inbox and a threshold 92
for emails that should probably go into the spam folder. 93
When you have a spam filter or an artificially intelligent program that is able to differentiate emails 94
that come in, whether if they should head to the inbox or whether if they should head to the spam box, 95
then it's kind of binary. 96
You can't really have a halfway house, like maybe a decontamination zone or a sort of spam or maybe spam 97
folder, 98
right? 99
So let's say that the decision is only binary when this machine learning model gets fed new testing 100
data in the form of an email, it should be able to scan through the contents and decide whether if it 101
should be sent to the inbox or whether if it should be sent to the spam box. 102
So it's a 1 or 0. 103
Now let's say that we train this model on a whole bunch of emails which are labeled as spam or not spam. 104
Now, let's say that one of the factors that affect whether if an email is likely to be spam is the number 105
of links that are contained in the actual email. 106
And this is a real thing, by the way. 107
If you try and go on the Gmail and you send somebody an email that has a hundred links, you can see which 108
folder it lands in. It's usually not going to be an inbox because it just looks so spammy. 109
So if we plot all of our training data onto this graph, so emails which are labeled spam or not spam, 110
based on the number of links that the email contains, then it might look something like this. 111
Now, the machine learning models job is to try and draw a line that goes through this data, and figures 112
out a threshold for the number of links. 113
So if, say, the number of links was less than five, then it probably is more likely to go into the inbox. 114
And if it's greater than five, it's probably more likely to be spam. 115
So it should go into the spam box. 116
And this particular rule can be given a weight amongst many, many other features. 117
For example, the number of images that are contained in the email or the number of words like buy or 118
sale. 119
So it evaluates a whole bunch of these features within the email and it has different weightings towards 120
each of these features. And using all of that, it's able to decide whether if an email should be going 121
to spam or going into the inbox. And it learns continuously over time. 122
So every single time you mark an email as spam, then you're teaching that machine learning algorithm 123
something new, whether if it's confirming its existing model or giving it new features or giving it new 124
data to work on to be able to predict this with increasing accuracy. 125
Now, the thing to remember is that in supervised learning, we've already spoken about classification problems. 126
And classification problems tend to be applied when you have discrete data, data that fit into specific 127
camp. 128
So for example, your grades, 129
right? 130
You might get an A+, you might get an A, a B, B+, et cetera. You won't get like, you know, a B+ .5, or 131
5, or a B+ .599, instead, 132
that would be called Continuous Data. 133
So if, for example, your height, right? Your height could be anywhere along a ruler and depending on how 134
accurately you decide to measure your height, you know, it could go down to 10 decimal places if you were 135
really that interested in your precise height. 136
So the reason why we differentiate between discrete and continuous data is that when you're working 137
with continuous data with machine learning, you're more likely to be using a process called regression 138
to do your machine learning. 139
So a good example of a regression model is, for example, developer salaries, 140
right? 141
So according to indeed.com, the average salary of a developer, it doesn't say what kind of developer, 142
is about 100,000 per year. 143
And this is based on data from about 1,500 employees over the past 12 months. 144
It also shows you this box depending on the level of experience of the developer. 145
They might get paid less or more. 146
So this is something that we would probably tend to agree with, 147
right? 148
If you've worked for a longer number of years at a particular job, you're probably going to get paid 149
more. 150
Now, say, if you had a friend who came to you and said, "I worked as a developer for 12 years. How much do 151
you think that I'm likely to get paid if I apply for a job right now?" 152
Now, you can given them a rough estimate putting him into one of these camps, right? 153
Maybe 12 years puts you into, you know, your average developer, or maybe if he's worked for 20 years and 154
that puts him into the senior developer camp. But you can't really say for sure exactly what number should 155
be based on his exact input, i.e., 12 years. 156
So this is where a regression learning model comes in handy. 157
Let's say that you plot a graph of developer salaries and on the Y axis, you've got the salary, and on 158
the X axis, you've got the years of experience. 159
So you're looking at the years of experience as an independent variable to the salary of a developer. 160
So this is what that graph looks like 161
if you give it a whole bunch of training data, i.e., clearly label data. 162
So each data point has a salary amount and the years of experience of that developer who is earning 163
that salary. 164
Now, in most cases, even if you have zero years of experience, you're not going to start out with a salary 165
of zero, 166
because even interns get paid, 167
right? 168
So that first data point is maybe the entry-level standard salary. 169
But as you can see, using your human eye, as the years of experience increase, you generally see an increase 170
in the amount of salary they earn. 171
Now, if I told you to try and draw a line through all the data that best fits this particular data set, 172
you might be able to do it quite easily. 173
And similarly, this is what we want our regression model to do, 174
we wanted to draw a line through the data that best fits this particular dataset. 175
And now that we have our regression model, we're able to go and go into the X axis and look at where 176
12 years of experience will hit the line at. 177
And then if we extend it to the Y axis, we can see based on our training data what amount of salary our 178
friend, who has 12 years of developer experience, should be earning. 179
So this is a very, very simple representation of a regression model. 180
Now, of course, there's other types of supervised learning models, but the most common ones that you will 181
see and the most common ones are used commercially are regression and classification, both of which CoreML 182
is able to do. Now, in the next lesson, we're going to talk about another type of machine learning 183
which is unsupervised learning. 184
So I'll see you there.