Same Branch?

Machine Learning in CodeMedium+10 XP+10

Same Branch?

A tailor records customers as [height_cm, weight_kg]. She wants to know whether two particular customers would land in the same size group.

Heights and weights are in different units, so she scales first.

Task: write same_group(people, n_groups, pairs).

  • Scale the columns with StandardScaler().fit_transform(...).
  • Fit AgglomerativeClustering(n_clusters=n_groups) on the scaled data, with the default linkage.
  • pairs is a list of [i, j] row-index pairs. For each pair, in order, return True if rows i and j got the same cluster, and False if not.

Return the list of booleans. Make sure each one is a plain Python bool.

Examples

people = [[150, 45], [152, 47], [149, 44], [188, 46], [190, 44], [151, 90], [153, 92], [189, 91], [191, 89]]
n_groups = 4
pairs = [[0, 1], [0, 3], [5, 6], [7, 8]]
returns [True, False, True, True]
people = [[150, 45], [152, 47], [149, 44], [188, 46], [190, 44], [151, 90], [153, 92], [189, 91], [191, 89]]
n_groups = 2
pairs = [[0, 3], [0, 5], [3, 7]]
returns [True, False, False]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run