Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q5 of 15
SciPy - Clustering and Distance
What will be the output of the following code?
from scipy.cluster.vq import kmeans
import numpy as np

data = np.array([[1, 1], [2, 2], [10, 10], [11, 11]])
centroids, distortion = kmeans(data, 2)
print(len(centroids))
A0
B4
C1
D2
Step-by-Step Solution
Solution:
  1. Step 1: Understand kmeans output

    kmeans returns centroids array with number of clusters specified (2 here).
  2. Step 2: Check length of centroids

    Since 2 clusters requested, centroids array length is 2.
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    Number of centroids = number of clusters = 2 [OK]
Quick Trick: kmeans returns centroids equal to requested cluster count [OK]
Common Mistakes:
  • Confusing data points count with centroids
  • Expecting distortion length
  • Assuming centroids length equals data length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes