Introduction to Machine Learning
Transcript
[MUSIC PLAYING] BRIAN YU: All right, welcome back, everyone, to an introduction to Artificial Intelligence with Python. Now so far in this class, we've used AI to solve a number of different problems-- giving the AI instructions for how to search for a solution or how to satisfy certain constraints in order to find its way from some input point to some output point in order to solve some sort of problem. Today, we're going to turn to the world of learning in particular the idea of machine learning
which generally refers to the idea where we are not going to give the computer explicit instructions for how to perform a task, but rather, we are going to give the computer access to information in the form of data or patterns that it can learn from, and let the computer try and figure out what those patterns are-- try and understand that data to be able to perform a task on its own. Now machine learning comes in a number of different forms and it's a very wide field. So today, we'll explore some of the foundational algorithms and ideas that are behind a lot of the different areas within machine learning. And one of the most popular is the idea of supervised machine learning or just supervised learning. And supervised learning is a particular type of task. It refers to the task where we give the computer access to a data set, where that data set consists of input-output pairs. And what we would like the computer to do
is we would like our AI to be able to figure out some function that maps inputs to outputs. So we have a whole bunch of data that generally consists of some kind of input-- some evidence, some information that the computer will have access to. And we would like the computer, based on that input information, to predict what some output is going to be. And we'll give it some data so that the computer can train its model on to begin to understand how it is that this information works, and how it is that the inputs and outputs relate to each other. But ultimately, we hope that our computer will be able to figure out some function that given those inputs, is able to get those outputs. There are a couple of different tasks within supervised learning, the one we'll focus on and start with is known as classification. And classification is the problem where if I give you a whole bunch of inputs, you need to figure out some way to map those inputs
into discrete categories, where you can decide what those categories are. And it's the job of the computer to predict what those categories are going to be. So that might be, for example, I give you information about a banknote like a US dollar and I'm asking you to predict for me doesn't belong to the category of authentic bank notes or does it belong to the category of counterfeit banknotes. You need to categorize the input. And we want to train the computer to figure out some function to be able to do that calculation. Another example might be the case of weather, something we've talked about a little bit so far in this class, where we would like to predict on a given day is it going to rain on that day, is it going to be cloudy on that day. And before, we've seen how we could do this, if we really give the computer all the exact probabilities for, you know, if these are the conditions, what's the probability of rain,
oftentimes, we don't have access to that information, though. But what we do have access to is a whole bunch of data. So if we wanted to be able to predict something like is it going to rain or is it not going to rain, we would give the computer historical information about days when it was raining and days when it was not raining, and ask the computer to look for patterns in that data. So what might that data look like? Well, we could structure that data in a table like this. This might be what our table looks like, where are for any particular day going back, we have information about like that day's humidity, that day's air pressure. And then importantly, we have a label-- something where the human has said that on this particular day, it was raining or it was not raining. So you could fill in this table with a whole bunch of data. And what makes this what we would call a supervised learning exercise
is that a human has gone in and labeled each of these data points. Said that on this day, when these were the values for the humidity and pressure, that day was a rainy day and this day was a not rainy day. And what we would like the computer to be able to do then is to be able to figure out, given these inputs, given the humidity and the pressure, can the computer predict what label should be associated with that day. Does that day look more like it's going to be a day that rains or does it look more like a day when it's not going to rain. Put a little bit more mathematically, you can think of this as a function that takes two inputs-- the inputs being the data points that our computer will have access to-- things like humidity and pressure. So we could write a function, f, that takes as input both humidity and pressure. And then the output is going to be what category we would ascribe to these particular input points-- what label
we would associate with that input. So we've seen a couple of example data points here, where given this value for humidity and this value for pressure, we predict is it going to rain or is it not going to rain. And that's information that we just gathered from the world. We measured on various different days what the humidity and pressure were. We observed whether or not we saw rain or no rain on that particular day. And this function, f, is what we would like to approximate. Now the computer and we humans don't really know exactly how this function f works-- it's probably quite a complex function. So what we're going to do instead is attempt to estimate it. We would like to come up with a hypothesis function, h, which is going to try to approximate what f does. We want to come up with some function h that will also take the same inputs and we'll also produce an output, rain or no rain. And ideally, we'd like these two functions to agree on as much as possible.
So the goal then of these supervised learning classification tasks is going to be to figure out what does that function h look like. How can we begin to estimate, given all of this information, all of this data, what category or what label should be assigned to a particular data point. So where can you begin doing this? Well, a reasonable thing to do, especially in this situation-- I have two numerical values-- is I could try to plot this on a graph that has two axes-- an x-axis and the y-axis. And in this case, we're just going to be using two numerical values as input, but these same types of ideas at scale as you add more and more inputs as well. We'll be plotting things in two dimensions, but as we'll soon see, you could add more inputs and just imagine things in multiple dimensions. And while we humans have trouble conceptualizing anything really beyond three dimensions, at least visually, a computer has no problem with trying to imagine things and many, many more dimensions.
That for a computer, each dimension is just some separate number that are just keeping track. So it wouldn't be unreasonable for a computer to think in 10 dimensions or 100 dimensions to be able to try to solve a problem. But for now, we've got two inputs, so we'll graph things along two axes-- an x-axis, which will here represent humidity, and a y-axis, which here represents pressure. And what we might do is say, let's take all of the days that were raining, and just try to plop them on this graph, and see where they fall on this graph. And here might be all of the rainy days, where each rainy day is one of these blue dots here that corresponds to a particular value for humidity and a particular value for pressure. And then I might do the same thing with the days that were not raining. So I take all the not rainy days, figure out what their values were for each of these two inputs, and go ahead and plot them on this graph as well.
And I've here plotted them in red. So blue here stands for a rainy day, red here stands for a not rainy day. And this then is the input-- that my computer has access to all of this input. And what I would like the computer to be able to do is to train a model such that if I'm ever presented with a new input that doesn't have a label associated with it, something like this white dot here, I would like to predict given those values for each of the two inputs, should we classify it as a blue dot, a rainy day, or should we classify it as a red dot, a not rainy day. And if you're just looking at this picture graphically trying to say, all right, this white dot, does it look like it belongs to the blue category or does it look like it belongs to the red category, I think most people would agree that it probably belongs to the blue category. And why is that? Well, it looks like it's close to other blue dots.
And that's not a very formal notion, but it's the notion that we'll formalize it in just a moment-- that because it seems to be close to, like, this blue dot here, like, nothing else it's closer to it, than we might say that it should be categorized as blue. It should fall into that category of, I think that day is going to be a rainy day based on that input. It might not be totally accurate, but it's a pretty good guess. And this type of algorithm is actually a very popular and common machine learning algorithm known as nearest neighbor classification. It's an algorithm for solving these classification type problems. And in nearest neighbor classification, it's going to perform this algorithm. What it will do is, given an input, it will choose the class of the nearest data point to that input. By class, we just here mean category, like rain or no rain, counterfeit or not counterfeit. And we choose the category or the class based on the nearest data point.
So given all that data we just looked at, is the nearest data point a blue point or is that a red point. And depending on the answer to that question, we were able to make some sort of judgment. We were able to say something like, we think it's going to be blue or we think it's going to be red. So likewise, we could apply this to other data points that we encounter as well. If suddenly, this data point comes about, well, it's nearest data is red, so we would go ahead and classify this as a red point, not raining. Things get a little bit trickier, though, when you look at a point like this white point over here, and you ask the same sort of question-- should it belong to the category of blue points, the rainy days? Or should it belong to the category of red points, the not rainy days? Now nearest neighbor classification would say the way you solve this problem is look at which point it is nearest to that point.
You look at this nearest point and say it's red-- it's a not rainy day. And therefore, according to nearest neighbor classification, I would say that this unlabeled point, that should also be red. It should also be classified as a not rainy day. But your intuition might think that that's a reasonable judgment to make-- that the closest thing is a not rainy day, so may as well guess that it's not rainy day. But it's probably also reasonable to look at the bigger picture of things and to say, yes, it is true, that the nearest point to it was a red point, but it's surrounded by a whole bunch of other blue points. So looking at the bigger picture, there is potentially an argument to be made that this point should actually be blue. And with only this data, we actually don't know for sure. We are given some inputs, something we're trying to predict, and we don't necessarily know what the output is going to be. So in this case, which one is correct is difficult to say.
But oftentimes, considering more than just a single neighbor, considering multiple neighbors, can sometimes give us a better result. And so there's a variant on the nearest neighbor a classification algorithm that is known as the k-nearest-neighbor classification algorithm, where k is some parameter, some number that we choose for how many neighbors are we going to look at. So one nearest neighbor classification is what we saw before. Just pick the one nearest neighbor and use that category. But with k-nearest-neighbor classification, where k might be three or five or seven-- to say look at the three or five or seven closest neighbors, closest data points to that point, works a little bit differently. This algorithm, we're given an input. Choose the most common class out of the k nearest data points to that input. So if we look at the five nearest points, and three of them say it's raining and two of them say it's not raining, we'll go with the three instead of the two,
because each one effectively gets one vote towards what they believe the category ought to be. And ultimately, you choose the category that has the most votes as a consequence of that. So k-nearest-neighbor classification-- fairly straightforward one to understand intuitively. You just look at the neighbors and figure out what the answer might be. And it turns out this can work very, very well for solving a whole variety of different types of classification problems. But not every model is going to work under every situation. And so one of the things we'll take a look at today, especially in the context of supervised machine learning is that there are a number of different approaches to machine learning-- a number of different algorithms that we can apply all solving the same type of problem. All solving some kind of classification problem, where we want to take inputs and organize it into different categories
And no one algorithm isn't necessarily always going to be better than some other algorithm. They each have their trade-offs. And maybe depending on the data, one type of algorithm is going to be better-suited to trying to model that information than some other algorithm. And so this is what a lot of machine learning research ends up being about-- that when you're trying to apply machine learning techniques, you're often looking not just at one particular algorithm, but trying multiple different algorithms, trying to see what is going to give you the best results for trying to predict some function that maps inputs to outputs. So what then are the drawbacks of k-nearest-neighbor classification? Well, there are a couple. One might be that in a naive approach at least, it could be fairly slow to have to go through and measure the distance between a point and every single one of these points that exist here. Now there are ways of trying to get around that.
There are data structures that can help to make it more quickly to be able to find these neighbors. There are also techniques you can use to try and prune some of this data, remove some of the data points so that you're only left with the relevant data points just to make it a little bit easier. But ultimately, what we might like to do is come up with another way of trying to do this classification. And one way of trying to do the classification was looking at what are the neighboring points. But another way might be to try to look at all of the data and see if we can come up with some decision boundary-- some boundary that will separate the rainy days from the not rainy days. In the case of two dimensions, we can do that by drawing a line, for example. So what we might want to try to do is just find some line, find some separator that divides the rainy days, the blue points over here, from the not rainy days, the red points over there.
We're now trying a different approach in contrast with the nearest neighbor approach, which just looked at local data around the input data point that we cared about. Now what we're doing is trying to use a technique known as linear regression to find some sort of line that will separate the two halves from each other. Now, sometimes, it will actually be possible to come up with some line that perfectly separates all the rainy days from the not rainy days. Realistically, though, this is probably cleaner than many data sets will actually be. Oftentimes, data is messy. There are outliers. There's random noise that happens inside of a particular system. And what we'd like to do is still be able to figure out what a line might look like. So in practice, the data will not always be linearly separable, where linearly separable refers to some data set where I can draw a line just to separate the two halves of it perfectly.
Instead, you might have a situation like this, where there are some rainy points that are on this side of the line and some not raining points that are on that side of the line. And there may not be a line that perfectly separates what path of the inputs from the other half-- that perfectly separates all the rainy days from the not rainy days. But we can still say that this line does a pretty good job. And we'll try to formalize a little bit later. What we mean when we say something like this line does a pretty good job of trying to make that prediction. But for now, let's just say we're looking for a line that does as good of a job as we can at trying to separate one category of things from another category of things. So let's now try to formalize this a little bit more mathematically. We want to come up with some sort of function, some way we can define this line. And our inputs are things like humidity and pressure in this case.
So our inputs we might call x1 is going to be our represent humidity and x2 is going to represent pressure. These are inputs that we are going to provide to our machine learning algorithm. And given those inputs, we would like for our model to be able to predict some sort of output. And we're going to predict that using our hypothesis function, which we called h. Our hypothesis function is going to take as input, x1 and x2, humidity and pressure in this case. And you can imagine if we didn't just have two inputs-- we had three or four or five inputs or more-- we could have this hypothesis function take all of those as input. And we'll see examples of that a little bit later as well. And now the question is, what does this hypothesis function do? Well, it really just needs to measure is this data point on one side of the boundary or is it on the other side of the boundary? And how do we formalize that boundary?
Well, the boundary is generally going to be a linear combination of these input variables, at least in this particular case. So what we're trying to do when we say linear combination is take each of these inputs and multiply them by some number that we're going to have to figure out. We'll generally call that number a weight for how important should these variables be in trying to determine the answer. So weight each of these variables with some weight. And we might add like a constant to it just to try and make the function a little bit different. And the result we just need to compare-- is it greater than 0 or is it less than 0 to say doesn't belong on one side of the line or the other side of the line. And so what that mathematical expression might look like is this. We would take each of my variables, x1 and x2, multiply them by some weight. I don't yet know what that weight is, but it's going to be some number, weight 1 and weight 2.
And maybe we just want to add some other weight 0 to it because the function might require us to shift the entire value up or down by a certain amount. And then we just compare. If we do all this math, is a greater than or equal to 0. If so, we might categorize that data point as a rainy day. And otherwise, we might say no rain. So the key here then is that this expression is how we are going to calculate whether it's a rainy day or not. We're going to do a bunch of math where we take each of the variables, multiply them by a weight, maybe add an extra weight to it, see if the result is greater than or equal to 0. And using that result of that expression, we're able to determine whether it's raining or not raining. This expression here is in this case going to refer to just some line. If you were to plot that graphically, it would just be some line. And what the line actually looks like depends upon these weights.
x1 and x2 are the inputs, but these weights are really what determine the shape of that line, the slope of that line, and what that line actually looks like. So we then would like to figure out what these weights should be. We can choose whatever weights we want, but we want to choose weights in such a way that if you pass in a rainy day's humidity and pressure, then you end up with a result that is greater than or equal to 0. And we would like it such that if we passed into our hypothesis function, a not rainy day's inputs, then the output that we get should be not raining. So before we get there, let's try and formalize this a little bit more mathematically just to get a sense for how it is that you'll often see this if you ever go further into a supervised machine learning and explore this idea. One thing is that generally for these categories,
we'll sometimes just use the names of the categories like rain and not rain. Often, mathematically, if we're trying to do comparisons between these things, it's easier just to deal in the world of numbers. So we could just say 1 and 0-- 1 for raining, 0 for not raining. So we do all this math. And if the result is greater than or equal to 0, we'll go ahead and say our hypothesis function outputs 1, meaning raining. And otherwise, it outputs 0, meaning not raining. And oftentimes, this type of expression will instead express using vector mathematics. And all the vector is, if you're not familiar with the term, is it refers to a sequence of numerical values. You could represent that in Python using, like, a list of numerical values or a tuple with numerical values. And here, we have a couple of sequences of numerical values. One of our vectors, one of our sequences of numerical values, are all of these individual weights-- w0, w1 and w2.
So we could construct what we'll call a weight vector and we'll see why this is useful in a moment called w, generally represented using a boldface w, that is just a sequence of these three weights-- weight 0, weight 1, and weight 2. And to be able to calculate based on those weights whether we think a day is raining or not raining, we're going to multiply each of those weights by one of our input variables. That w2, this weight, is going to be multiplied by input variable x2. w1 is going to be multiplied by input variable x1. And w0-- well, it's not being multiplied by anything, but to make sure the vectors are the same length-- and we'll see why that's useful in just a second-- we'll just go ahead and say w0 is being multiplied by 1. Because you can multiply by something by 1 and you end up getting the exact same number. So in addition to the weight vector, w, we'll also have an input vector that we'll call x that has three values--
1, again, because we're just multiplying w0 by 1 eventually, and then x1 and x2. So here then, we've represented two distinct vectors-- a vector of weights that we need to somehow learn. The goal of our machine learning algorithm is to learn what this weight vector is supposed to be. We could choose any arbitrary set of numbers and it would produce a function that tries to predict rain or not rain, but it probably wouldn't be very good. What we want to do is come up with a good choice of these weights so that we're able to do the accurate predictions. And then this input vector represents a particular input to the function, a data point for which we would like to estimate, is that day a rainy day or is that day not rainy day. And that's going to vary just depending on what input is provided to our function, what it is that we are trying to estimate. And then to do the calculation, we want to calculate this expression here.
And it turns out that expression is what we would call the dot product of these two vectors. The dot product of two vectors just means taking each of the terms and the vectors and multiplying them together, w0 multiplied by 1, w1 multiplied it by x1, w2 multiply it by x2. And that's why these vectors need to be the same length. And then we just add all of the results together. So the dot product of w and x, our weight vector and our input vector, that's just going to be w0 times 1, or just w0 plus w1 times x1, multiplying these two terms together, plus w2 times x2, multiplying those statements together. So we have our weight vector, which we need to figure out. We need our machine learning algorithm to figure out what the weights should be. We have the input vector representing the data point that we're trying to predict a category for, predict a label for. And we're able to do that calculation by taking this dot product, which you'll
often see represented in vector form-- but if you haven't seen vectors before, you can think of it as identical to just this mathematical expression. Just doing the multiplication, adding the results together. And then seeing whether the result is greater than or equal to 0 or not. This expression here is identical to the expression that we're calculating to see whether or not that answer is greater than or equal to 0 in this case. And so for that reason, you'll often see the hypothesis function written as something like this-- a simpler representation where the hypothesis takes as input some input vector x, some humidity and pressure for some day. And we want to predict an output like rain or no rain or 1 or 0 if we choose to represent things numerically. And the way we do that is by taking the dot product of the weights and our input. If it's greater than or equal to 0, we'll go ahead and save the output is 1. Otherwise, the output is going to be 0.
And this hypothesis we say is parameterized by the weights. Depending on what weights we choose, we'll end up getting a different hypothesis. If we choose the weights randomly, we're probably not going to get a very good hypothesis function. We'll get a 1 or a 0, but it's probably not accurately going to reflect whether we think a day is going to be rainy or not rainy. But if we choose the weights right, we can often do a pretty good job of trying to estimate whether we think the output of the function should be a 1 or a 0. And so the question then, is how to figure out what these weights should be-- how to be able to tune those parameters. And there are a number of ways you can do that. One of the most common is known as the perceptron learning rule. And we'll see more of this later. But the idea of the perceptron learning rule-- and we're not going to get too deep into the mathematics, we'll mostly just introduce it more conceptually-- is
to say that given some data point that we would like to learn from, some data point that has an input x and an output y, where y is like 1 for rain or 0 for not rain, then we're going to update the weights. And we'll look at the formula in just a moment. But the big picture idea is that we can start with random weights but then learn from the data. Like, take the data points one at a time. And for each one of the data points figure out, all right, what parameters do we need to change inside of the weights in order to better match that input point. And so that is the value of having access to a lot of data in the supervised machine learning algorithm-- is that you take each of the data points and maybe look at the multiple times and constantly try and figure out what you whether you need to shift your weight in order to better create some weight vector that is able to correctly or more accurately
try to estimate what the output should be. Whether we think it's going to be raining or whether we think it's not going to be raining. So what does that weight update look like? Without going into too much of the mathematics, we're going to update each of the weights to be the result of the original weight plus some additional expression. And to understand this expression y-- well, y is what the actual output is. And hypothesis of x, the input, that's going to be what we thought the input was. And so I can replace this by saying what the actual value was minus what our estimate was. And based on the difference between the actual value and what our estimate was, we might want to change our hypothesis, change the way that we do that estimation. If the actual value and the estimate were the same thing, meaning we were correctly able to predict what category this data point belonged to, well, then actual value minus estimate, that's just going to be 0,
which means this whole term on the right hand side goes to be 0. And the weight doesn't change. Weight i, where i is weight 1 or weight 2 or weight 0, weight i just stays at weight i. And none of the weights change if we were able to correctly predict what category the input belonged to. But if our hypothesis didn't correctly predict what category the input belonged to, then maybe then we need to make some changes-- adjust the weights so that we're better able to predict this kind of data point in the future. And what is the way we might do that? Well, if the actual value was bigger than the estimate, then-- and for now, we'll go ahead and assume that these is are positive values-- if the actual value is bigger than the estimate, that means we need to increase the weight in order to make it such that the output is bigger and therefore, we're more likely to get to the right actual value. And so if the actual value is bigger than the estimate,
then actual value minus estimate, that'll be a positive number. And so you imagine we're just adding some positive number to the weight just to increase it ever so slightly. And likewise, the inverse case is true-- that if the actual value was less than the estimate, the actual value was 0, but we estimated 1, meaning it actually was not raining, but we predicted it was going to be raining, then we want to decrease the value of the weight, because then in that case, we want to try and lower the total value of computing that dot product in order to make it less likely that we would predict that it would actually be raining. So no need to get too deep into the mathematics of that. But the general idea is that every time we encounter some data point, we can adjust these weights accordingly to try and make the weights better line up with the actual data that we have access to. And you can repeat this process with data point after data point
until eventually, hopefully, your algorithm converges to some set of weights that do a pretty good job of trying to figure out whether a day is going to be rainy or not rainy. And just as a final point about this particular equation, this value alpha here is generally what we'll call the learning rate. It's just some parameter, some number we choose it for how quickly we're actually going to be updating these weight values. That if alpha is bigger, than we're going to update these weight values by a lot. And if alpha is smaller, then we'll update the weight values by less. And you can choose the value of alpha depending on the problem, different values might suit the situation better or worse than others. So after all of that, after we've done this training process, take all this data, and using this learning rule, look at all the pieces of data, and use each piece of data as an indication to us of do the weights stay the same, do we increase the weights,
do we decrease the weights, and if so, by how much, what you end up with is effectively a threshold function. And we can look at what the threshold function looks like like this. On the x-axis here, we have the output of that function. Taking the weights taking, the dot product of it with the input. And on the y-axis, we have what the output is going to be. 0, which in this case represented like not raining, and 1, which in this case, represented raining. And the way that our hypothesis function works is it calculates this value. And if it's greater than 0 or greater than some threshold value, then we declare that it's a rainy day. And otherwise, we declare that it's not rainy day. And this then graphically is what that function looks like. That Initially, when the value of this dot product is small-- it's not raining, it's not raining, it's not raining-- but as soon as it crosses that threshold, we suddenly say,
OK, now it's raining, now it's raining, now it's raining. And the way to interpret this kind of representation is that anything on this side of the line, that would be the category of data points where we say yes, it's raining. Anything that falls on this side of the line are the data points where we would say it's not raining. And again, we want to choose some value for the weights that results in a function that does a pretty good job of trying to do this estimation. But one tricky thing with this type of hard threshold is that it only leaves two possible outcomes. We plug-in some data as input. And the output we get is raining or not raining. And there is no room for it anywhere in between. And maybe that's what you want. Maybe all you want is given some data point, you would like to be able to classify it into one or two or more of these various different categories. But it might also be the case that you care
about knowing how strong that prediction is, for example. So if we go back to this instance here, where we have rainy days on this side of the line, not rainy days on that side of the line, you might imagine that let's look now at these two white data points. This data point here that we would like to predict a label or a category for. And this data point over here that we would also like to predict a label or a category for. It seems likely that you could pretty confidently say that this data point, that should be a rainy day. It seems close to the other rainy days if we're going by the nearest neighbor strategy. It's on this side of the line if we're going by the strategy of just saying which side of the line does it fall on by figuring out what those weights should be. And if we're using the line strategy of just which side of the line does it fall on, which side of this decision boundary,
we'd also say that this point here is also a rainy day, because it falls on the side of the line that corresponds to rainy days. But it's likely that even in this case, we would know that we don't feel nearly as confident about this data point on the left as compared to this data point on the right. For this one on the right, we can feel very confident that, yes, it's a rainy day. This one, it's pretty close to the line if we're judging just by distance. And so you might be less sure. But our threshold function doesn't allow for a notion of less sure or more sure about something. It's what we would call a hard threshold. It's once you've crossed this line, then immediately, we say, yes, this is going to be a rainy day. Anywhere before it, we're going to say it's not a rainy day. And that may not be helpful in a number of cases. One, this is not a particularly easy function to deal with. If you get you get deeper into the world of machine learning
and are trying to do things like taking derivatives of these curves, this type of function makes things challenging. But the other challenge is that we don't really have any notion of gradation between things. We don't have a notion of, yes, this is a very strong belief that it's going to be raining as opposed to it's probably more likely than not that it's going to be raining, but maybe not totally sure about that, either. So what we can do by taking advantage of a technique known as logistic regression is instead of using this hard threshold type of function, we can use instead a logistic function, something we might call a soft threshold. And that's going to transform this into looking something a little more like this-- something that more nicely curves. And as a result, the possible output values are no longer just 0 and 1, 0 for not raining, 1 for raining. But you can actually get any real number of value between 0 and 1.
That if you're way over on this side, then you get a value of 0-- it's not going to be raining, we're pretty sure about that. And if you're over on this side, you get a value of 1-- yes, we're very sure that it's going to be raining. But in between, you could get some real numbered value where a value like 0.7 might mean we think it's going to rain. It's more probable that it's going to rain than not based on the data, but we're not as confident as some of the other data points might be. So one of the advantages of the soft threshold is that it allows us to have an output that could be some real number that potentially reflects some sort of probability, the likelihood that we think that this particular data point belongs to that particular category. And there are some other nice mathematical properties of that as well. So that then is two different approaches to trying to solve this type of classification problem. One is this nearest neighbor type of approach, where you just
take a data point and look at the data points that are nearby to try and estimate what category we think it belongs to. And the other approach is the approach of saying, all right, let's just try and use linear regression, figure out what these weights should be, adjust the weights in order to figure out what line or what decision boundary is going to best separate these two categories. It turns out that another popular approach, a very popular approach if you just have a data set and you want to start trying to do some learning on it, is what we call the support vector machine. We're not going to go too much into the mathematics of the support vector machine, but we'll at least explore it graphically to see what it is that it looks like. And the idea or the motivation behind the support vector machine is the idea that there are actually a lot of different lines that we could draw, a lot of different decision boundaries
that we could draw to separate two groups. So for example, I had the red data points over here and the blue data points over here. One possible line I could draw is a line like this, that this line here would separate the red points from the blue points. And it does so perfectly. All the red points are on one side of the line. All the blue points around the other side of the line. But this should probably make you a little bit nervous. If you come up with a model and the model comes up with a line that looks like this. And the reason why is that you worry about how well it's going to generalize to other data points that are not necessarily in the data set that we have access to. For example, if there was a point that fell right here for example, on the right side of the line, then based on that, we might want to guess that it is in fact, a red point, but it falls on the side of the line where instead, we would estimate that it's a blue point instead.
And so based on that, this line is probably not a great choice just because it is so close to these various data points. We might instead prefer a diagonal line that just goes diagonally through the data set like we've seen before. But there too, there's a lot of diagonal lines that we could draw as well. For example, I could draw this diagonal line here, which also successfully separates all the red points from all of the blue points. From the perspective of something like a just trying to figure out some setting of weights that allows us to predict the correct output, this line will predict the correct output for this particular set of data every single time, because the red points are on one side and the blue points are on the other. But yet again, you should probably be a little nervous. Because this line is so close to these red points, even though we're able to correctly predict on the input data if there was a point that fell somewhere in this general area,

Ask anything
We've read this whole study set, so questions about it get the best answers.