Bird
0
0

What is wrong with this clustering code?

medium📝 Debug Q7 of 15
SciPy - Clustering and Distance
What is wrong with this clustering code?
from scipy.cluster.vq import vq
import numpy as np

data = np.array([[1, 2], [3, 4]])
centroids = np.array([[1, 2]])
labels, _ = vq(data, centroids)
print(labels)
AData must be a list, not numpy array
Bvq requires kmeans to be called first
COnly one centroid is provided but data has two points
Dvq cannot handle 2D data
Step-by-Step Solution
Solution:
  1. Step 1: Check centroids vs data points

    Only one centroid is given but data has two points, so clustering is limited.
  2. Step 2: Understand vq behavior

    vq assigns each point to nearest centroid; with one centroid, all points get label 0.
  3. Final Answer:

    Only one centroid is provided but data has two points -> Option C
  4. Quick Check:

    Centroids count should match clusters desired [OK]
Quick Trick: Number of centroids should match expected clusters [OK]
Common Mistakes:
  • Assuming vq needs kmeans first
  • Wrong data type assumption
  • Thinking vq can't handle 2D data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes