CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Artificial Intelligence / Learning From Data

Scale Your Features

Lesson 7 of 11 · 7 min · Free, no account needed

What you will learn

  • kNN adds up differences across features, so a feature with big numbers (grams) can drown out one with small numbers (centimetres).
  • Feature scaling puts features on similar ranges. Min-max: (x - min) / (max - min) gives 0 to 1.
  • Distance-based methods need scaling. A decision tree, which asks about one feature at a time, doesn't care.

Start the lesson

How the lesson goes

  1. Two critters differ by 3 cm in ears. Two others differ by 3 g in weight. To kNN, which difference matters more?

    Tap your answer on the scene, then Check.

  2. Watch how kNN measures distance.

    The kind depends on ears only. Slide kNN's ruler from raw numbers to scaled ones and watch the violet ring and the vote.

  3. Same critter, two rulers. Find where they disagree.

    Drag the violet critter on either map. Then Check when the two votes differ.

  4. Fixing the ruler has a name.

    Tap to reveal it.

    Feature scaling puts every feature on a similar range, so no feature wins just because its numbers are big.

    Min-max scaling: (x - min) / (max - min). The smallest value becomes 0, the largest becomes 1.

    Anything that measures distance across features, like kNN, needs it.

  5. Scale four weights by eye.

    The lightest critter is 200 g, the heaviest 800 g. Drag each weight to its spot on the 0 to 1 ruler. Then Check.

  6. Which methods break without scaling?

    Drag each card to a side, or tap it and then a side. Then Check.

  7. Unbreak kNN.

    This kNN measures in raw grams and centimetres, and it gets test critters wrong. Fix its ruler in as few moves as you can. Par is 1.

  8. Code: scale a whole column with a loop.

    Fill the two blanks with tiles (lists and for loops, from Lists: Many Boxes in a Row). Press Run, then Check.

  9. Your critter from step 3, on a fairly scaled map. Which critter is its nearest neighbour?

    Tap it, then Check.

  10. Next: what if the critters have no labels at all?

    These scaled critters are all grey. Drag two flags onto the map and watch every critter pick its nearest flag.

Previous lesson: Where to Draw the Line: Precision and Recall · Next lesson: Finding Groups: Clustering · Part of the course: Learning From Data

Lessons are interactive and need JavaScript. Turn it on to play them.

Loading TwiddleLab