Houses as lists of numbers (vectors)
Why it matters A network never sees a house, a word or a picture. It sees a list of numbers. Turning things into lists of numbers, and comparing those lists, is step one.
Describe a house by three numbers: size in tens of square metres, bedrooms, and distance to the station in km. House A is [8, 3, 1.5], house B is [9, 3, 2.0], house C is [4, 1, 6.0]. Each list is a vector: a point in a space with one direction per feature.
Tiny numbers
How different are A and B? Subtract feature by feature: [-1, 0, -0.5]. Square each: [1, 0, 0.25]. Add up: 1.25. Square root: about 1.12. That is the straight-line distance between the two points. A and C come out at about 6.34, so B is the closer match to A.
Vector: an ordered list of numbers, one per feature. Distance: the length of the straight line between two vectors, np.linalg.norm(a - b).
Recap Things become vectors; similar things become nearby points.
Words and symbols in this lesson
- vector
- a list of numbers, one per feature
Write distance(a, b) (straight-line distance between two vectors, no loops) and most_similar(target, houses), which returns the index of the row in the 2D array houses closest to target.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.