Do Two Methods Agree?

Machine Learning in CodeMedium+10 XP+10

Do Two Methods Agree?

On real data you have no answer key. One check you can run is whether two different methods find the same groups. The wine data happens to have a hidden answer too, so you can see how much that check is worth.

Task: write agreement(k).

  • Load load_wine(return_X_y=True, as_frame=True) and scale the 13 columns with StandardScaler().fit_transform(X).
  • Cluster the scaled data twice with k groups:
    • KMeans(n_clusters=k, random_state=0, n_init=10)
    • AgglomerativeClustering(n_clusters=k) with the default linkage
  • Return a dict with three adjusted_rand_score values, each a plain float rounded to 3 decimal places:
    • "methods": k-means labels against the hierarchical labels
    • "kmeans_vs_truth": y against the k-means labels
    • "tree_vs_truth": y against the hierarchical labels

Examples

k = 3
returns {'methods': 0.853, 'kmeans_vs_truth': 0.897, 'tree_vs_truth': 0.79}
k = 2
returns {'methods': 0.765, 'kmeans_vs_truth': 0.389, 'tree_vs_truth': 0.439}

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