Chapter 4 · Section 3 practice

K-Means: Assign, Average, Repeat

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. Count labels

Warm-up. Print the number of fitted labels.

Write your answer, then run it.

2. Read centre shape

Warm-up. Print the centre array shape.

Write your answer, then run it.

3. Count group sizes

Warm-up. Print sorted cluster membership counts.

Write your answer, then run it.

4. Calculate a manual centroid

Build your skills. Print the coordinate means for A,B,C.

Write your answer, then run it.

5. Read the objective

Build your skills. Print inertia rounded to three decimals.

Write your answer, then run it.

6. Assign a new nearby point

Build your skills. Predict the cluster of (1.5,1.5).

Write your answer, then run it.

7. Check a new point manually

Build your skills. Calculate squared distances from (1.5,1.5) to both centres; print the nearest-centre index.

Write your answer, then run it.

8. Verify group means

Challenge. Print whether group means equal the fitted centres in label order.

Write your answer, then run it.

9. Reconstruct WCSS

Challenge. Use each row’s assigned centre to calculate the total squared distance.

Write your answer, then run it.

10. Distinguish assignment and refitting

Challenge. Save centres, predict a new point, and print whether centres stayed unchanged.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.