Linear Algebra for Machine Learning - Vectors(Distance between points)-II
Let's move on to find the distance between points. Last time we discussed distance or length of a vector. Check it out here:
As always we will try to find the distance between two points in a 2-D space first.
We have two vectors 'P' and 'Q' respectively.
P = [a1,a2]
Q = [b1,b2]
Now we need to find the distance between this two points. As we see the distance between this two points form 'hypotenuse' of a right angle triangle. So we can apply the Pythagoras theorem here. But for that we need to know the length of the sides. So let x and y be the values of the sides, where
So the distance can be calculated as
Putting the values of x and y, we get the distance as
Similarly we can calculate the distance between two points in a 3-D space. For that lets place the points in a cube, making all the difference using a z-axis. Now the points have 3 axis.
P = [a1,a2,a3]
Q = [b1,b2,b3]
So lets consider a3 at a farther units than b3. For z-axis we need to find the difference in units between a3 and b3, similarly what we did for other axis. Applying Pythagoras theorem same as we did for 2-D space. So let x,y and z be the axis on which the points are defined. Same as 2-D space
So the distance can be calculated as
Putting the values of x,y and z we get the distance as
Now that's all about 2-D and 3-D space, but what about n-D space. As always, Linear Algebra is all about extending our findings on 2-D and 3-D space to n-D space. So one common thing that you might have noticed in the above formulas is for every new axis we have just added its corresponding values to the formula.
So let's consider two vectors in n-D space
P = [a1,a2,a3,a4....an]
Q = [b1,b2,b3,b4....bn]
As we want to get the distance between two points, we consider
Using Pythagoras theorem, distance can be calculated as
Now putting the values of the difference of each axis
So the general formula for distance between two points irrespective of its space is
Everything is fine, till this point, but why we need to know distance between two points. The reason is simple, consider this
We are assured the red point is a hot spot, and blue point is cold spot. The proximity of the grey point towards red or blue point will make it part of cold or hot spot. That's all I have got for this post. Thanks for stopping by.