Bird
0
0

Find the bug in this code:

medium📝 Debug Q7 of 15
SciPy - Clustering and Distance
Find the bug in this code:
from sklearn.metrics import silhouette_score
labels = [0, 0, 1, 1]
data = [[1, 2], [2, 1], [8, 9]]
score = silhouette_score(data, labels)
print(score)
AData and labels length mismatch
Bsilhouette_score requires 3 arguments
CLabels must be floats
DImport statement is wrong
Step-by-Step Solution
Solution:
  1. Step 1: Check data and labels length

    Data has 3 points, labels has 4 labels; lengths must match.
  2. Step 2: Confirm function argument requirements

    silhouette_score requires data and labels of same length.
  3. Final Answer:

    Data and labels length mismatch -> Option A
  4. Quick Check:

    Length mismatch error = A [OK]
Quick Trick: Data and labels must have same length [OK]
Common Mistakes:
  • Ignoring length mismatch
  • Thinking labels must be floats
  • Incorrect import assumption

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes