Bird
0
0

Identify the error in this code snippet for calculating Davies-Bouldin score:

medium📝 Debug Q14 of 15
SciPy - Clustering and Distance
Identify the error in this code snippet for calculating Davies-Bouldin score:
from scipy.spatial.distance import davies_bouldin_score

labels = [0, 0, 1, 1]
data = [[1, 2], [1, 4], [10, 2], [10, 4]]
score = davies_bouldin_score(data, labels)
print(score)
AData must be a numpy array, not list
BLabels and data length mismatch
CImporting davies_bouldin_score from wrong module
DDavies-Bouldin score requires true labels
Step-by-Step Solution
Solution:
  1. Step 1: Check import source

    Davies-Bouldin score is in sklearn.metrics, not scipy.spatial.distance.
  2. Step 2: Validate data and labels

    Data and labels lengths match and data as list works with sklearn, so no error there.
  3. Final Answer:

    Importing davies_bouldin_score from wrong module -> Option C
  4. Quick Check:

    Correct import is sklearn.metrics [OK]
Quick Trick: Davies-Bouldin score is in sklearn.metrics, not scipy [OK]
Common Mistakes:
  • Importing from scipy.spatial.distance
  • Assuming data must be numpy array
  • Thinking Davies-Bouldin needs true labels

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes