Bird
0
0

Given the code below, what will be the output of labels?

medium📝 Predict Output Q13 of 15
SciPy - Clustering and Distance
Given the code below, what will be the output of labels?
import numpy as np
from scipy.cluster.vq import kmeans, vq

data = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
centroids, _ = kmeans(data, np.array([[1, 2], [10, 2]]))
labels, _ = vq(data, centroids)
print(labels.tolist())
A[0, 0, 0, 1, 1, 1]
B[1, 1, 1, 0, 0, 0]
C[0, 1, 0, 1, 0, 1]
D[1, 0, 1, 0, 1, 0]
Step-by-Step Solution
Solution:
  1. Step 1: Understand data and centroids

    Data has two groups: points near (1, y) and points near (10, y). Kmeans with 2 clusters finds centroids near these groups.
  2. Step 2: Assign labels with vq

    Points near (1, y) get label 0, points near (10, y) get label 1. So first three points labeled 0, last three labeled 1.
  3. Final Answer:

    [0, 0, 0, 1, 1, 1] -> Option A
  4. Quick Check:

    Clusters split by x-coordinate: left=0, right=1 [OK]
Quick Trick: Group points by centroid proximity for labels [OK]
Common Mistakes:
  • Assuming labels are reversed
  • Mixing up label order
  • Expecting labels to be random

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes