Index Ai Academy
Foundation · Foundation mathShapes, angles and waves

Coordinates and distance

About 42 minLooking ahead: some prerequisites aren't done yet

Why this matters

Geometry in AI comes down to two questions: where is a point, and how far apart are two points? Coordinates answer the first with numbers, and Pythagoras answers the second. The same distance formula works with three coordinates, or three hundred, which is how a model decides that two pictures, two words or two customers are similar: their lists of numbers are close. This lesson builds that distance and uses it to make a first prediction. Along the way Python gets the tuple, a small fixed group of values that suits a point exactly, and you'll meet the catch that every distance-based model has to handle: the units of each number decide what "close" means.

  • Place points with coordinates, (x, y), over then up, in all four quadrants
  • Find the distance between two points with Pythagoras, in two coordinates or more
  • Store points as tuples in Python, write a distance function for any number of coordinates, and graph a distance
  • Predict from the nearest neighbor: in ML, "similar" means "close"
Quick check
Have a guess before you start. You walk 3 blocks east, then 4 blocks north. How far are you from where you started, in a straight line?

The math: where, and how far

Purpose. Turn "where" and "how far" into numbers.

A point on a flat grid is written (x, y): go over x, then up y, from the origin (0, 0). Negative x is left and negative y is down, so the two axes cut the plane into four quadrants. (3, 4) is up and right; (−2, 1) is up and left.

Pythagoras. In a right triangle with short sides a and b, the long side c satisfies

a2+b2=c2a^2 + b^2 = c^2

In plain words: square the two short sides and add them; the square root of that is the long side.

The 3-4-5 triangle is the classic: 9 + 16 = 25, and √25 = 5.