0
0
SciPydata~10 mins

Cluster evaluation metrics in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function for calculating the silhouette score.

SciPy
from sklearn.metrics import [1]
Drag options to blanks, or click blank then click option'
Asilhouette_score
Bconfusion_matrix
Cmean_squared_error
Daccuracy_score
Attempts:
3 left
💡 Hint
Common Mistakes
Importing classification metrics like accuracy_score instead of clustering metrics.
Confusing silhouette_score with confusion_matrix.
2fill in blank
medium

Complete the code to calculate the silhouette score for data X with labels y_pred.

SciPy
score = silhouette_score([1], y_pred)
Drag options to blanks, or click blank then click option'
Ay_pred
BX_train
Clabels_true
DX
Attempts:
3 left
💡 Hint
Common Mistakes
Passing cluster labels as the first argument instead of data.
Using training data variable names that are not defined.
3fill in blank
hard

Fix the error in the code to compute the adjusted Rand index between true labels and predicted labels.

SciPy
from sklearn.metrics import adjusted_rand_score
ari = adjusted_rand_score([1], y_pred)
Drag options to blanks, or click blank then click option'
Ay_pred
BX
Clabels_true
DX_train
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the data points instead of true labels.
Passing predicted labels twice.
4fill in blank
hard

Fill both blanks to create a dictionary of cluster sizes for each cluster label in y_pred.

SciPy
cluster_sizes = {label: y_pred.count([1]) for label in [2]
Drag options to blanks, or click blank then click option'
Alabel
By_pred
Cset(y_pred)
Dlabels_true
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable for keys or count.
Not converting to set to get unique labels.
5fill in blank
hard

Fill all three blanks to compute the completeness score between true labels and predicted labels.

SciPy
from sklearn.metrics import [1]
score = [1]([2], [3])
Drag options to blanks, or click blank then click option'
Acompleteness_score
Blabels_true
Cy_pred
Dadjusted_rand_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using adjusted_rand_score instead of completeness_score.
Swapping the order of true and predicted labels.