In this session, we will understand the maths behind Cannon can use nearest neighbor.
Came here, a neighbor concept is used both in a classification supervised learning algorithm and also
an unsupervised learning.
OK, so let's explain this using an example I am trying to find in this case whether this green ball
belongs to the group of blue balls or the group of Red Bulls.
So how will I find that out?
I will find the distance between this green ball and the nearest red and blue balls.
OK, so that is all I do.
And what is this key?
He is the number of data points that I'm considering for the purpose of determining whether this blue
ball belongs to a green ball, belongs to the Blue Group or to the red group.
So what I do is I'm taking four points, Suki's four.
So I compute the distance between this point and this Red Point.
Similarly, I compute the distance between this point on this point and with each of the two blue points.
So I compute the distance for four scenarios.
Right, because I'm considering for nearest neighbors, how will I compute the distance?
I use the equilibrium distance formula.
Right.
Suppose I have to find the distance between this and this point.
OK, this point is x1 come on way run on this point, this extra come out.
So the formula is x2 minus x1 the all squared plus Y to minus Y one the world square.
So I compute for such distances.
Clear.
OK.
The formula that I use this Euclidian, I can also use what is known as Manhattan distance, that is,
instead of finding the distance through a straight line like this, I compute the distance from here
to here.
That is the base and then the height.
OK, that's another way of computing the distance you can use any one of the two methods for computing
the distance.
OK, now let's explain this further using an example.
I have seven data points for height, age and the corresponding weight.
I'm being asked to predict the rate for the eighth data point that only Heighten agent provided.
OK, so how will I compute?
I compute the distance between this point five point eight height and age 37 with respect to each of
these five data points.
For that, I use the equilibrium formula right.
In the case of six and 40, how will they compute Euclidean distance?
It will be six minus five point eight.
The whole square plus 40, minus thirty seven, the whole square.
I add the two and then I take a square root.
Right.
I get a value of three point zero one.
Similarly, I compute five point eight and thirty seven.
I compare against six point one one twenty six.
So on and so forth.
I compute this equilibrium distance, ok.
However, I am considering nearest neighbor of three only.
OK, so I take.
These three points in the nearest neighbors right in the distance is lawyer, that means it is closer
to the.
Five point eight and thirty seven data point, right?
So I consider the three lawyers the distances and the corresponding rate, I think I add the three week
that is at 78 and 60, I am divided by three.
I'm taking an average and the wait I get is seventy two point six seven.
So the weight corresponding to the height of five point eight and thirty seven is seventy two point
six seven.
That is my prediction.
This is how I compute the predicted value using Cannon, just like in the case of regression and decision
tree, the entire process of computing the nearest neighbors is done using a prebuilt library that is
available both in Python as well as in R.
OK, is this clear?