Chapter 4 · Section 2 practice

Distance Measures and Standardisation

Work from question 1 to 10. Edit your Python box, click Run Code, review the result, then click Submit attempt. Reference answers unlock after all ten attempts are submitted. This records completion, not correctness. Each box runs independently. Progress is saved in this browser.

Submitted: 0 / 10

1. Calculate one coordinate gap

Warm-up. Print the Income difference A minus B.

Write your answer, then run it.

2. Calculate raw Euclidean distance

Warm-up. Print the raw A–B distance rounded to three decimals.

Write your answer, then run it.

3. Calculate Manhattan distance

Warm-up. Print raw A–B Manhattan distance.

Write your answer, then run it.

4. Check standardised means

Build your skills. Print the three standardised means rounded to six decimals.

Write your answer, then run it.

5. Check population SD

Build your skills. Print standardised population SDs.

Write your answer, then run it.

6. Compare SD conventions

Build your skills. Print sample and population SD of standardised Age.

Write your answer, then run it.

7. Calculate standardised distance

Build your skills. Print A–B Euclidean distance on the standardised features.

Write your answer, then run it.

8. Compare two neighbours

Challenge. Print standardised A–B and A–C distances.

Write your answer, then run it.

9. Transform a new customer

Challenge. Use the existing scaler for Age=30, Income=50000, Score=70 and print the result.

Write your answer, then run it.

10. Reconstruct a scaling calculation

Challenge. Manually standardise Income with ddof=0; print whether it matches the scaled Income column.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.