Chapter 4 · Section 6 practice

Extension: Hierarchical Clustering and Dendrograms

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 merge rows

Warm-up. Print the shape of Z.

Write your answer, then run it.

2. Read the first merge height

Warm-up. Print the first merge height rounded to three decimals.

Write your answer, then run it.

3. Read the final group size

Warm-up. Print the count stored in the final merge row.

Write your answer, then run it.

4. Cut below the first merge

Build your skills. Use cut height 0.5 and print the number of groups.

Write your answer, then run it.

5. Make a two-group cut

Build your skills. Use cut height 3 and print membership labels.

Write your answer, then run it.

6. Cut above the final merge

Build your skills. Use cut height 20 and print the group count.

Write your answer, then run it.

7. Inspect cut group sizes

Build your skills. At cut height 3, print membership counts.

Write your answer, then run it.

8. Calculate an average linkage gap

Challenge. Calculate the mean pairwise distance between {A,B} and {D,E}.

Write your answer, then run it.

9. Compare linkage choices

Challenge. Build a complete-linkage tree and print its final merge height beside Ward’s.

Write your answer, then run it.

10. Compare memberships without label IDs

Challenge. Fit KMeans K=2 and cut Ward at 3; compare the pairwise same-group matrices.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.