Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the clustering algorithm.
ML Python
from sklearn.cluster import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing train_test_split instead of a clustering algorithm.
Confusing clustering with regression or PCA.
✗ Incorrect
The KMeans class is used for clustering data points into groups.
2fill in blank
mediumComplete the code to fit the clustering model on data X.
ML Python
model = KMeans(n_clusters=3) model.[1](X)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using predict before fitting the model.
Using transform which is for dimensionality reduction.
✗ Incorrect
The fit method trains the clustering model on the data.
3fill in blank
hardFix the error in the code to predict cluster labels.
ML Python
labels = model.[1](X) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict to get labels.
Using transform which changes data representation.
✗ Incorrect
The predict method assigns cluster labels to data points after the model is fitted.
4fill in blank
hardFill both blanks to create a dictionary of cluster sizes.
ML Python
cluster_sizes = {i: sum(labels [1] i) for i in range([2])} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong counts.
Using len(labels) instead of number of clusters in range.
✗ Incorrect
We count how many labels equal each cluster index from 0 to 2 (3 clusters).
5fill in blank
hardFill all three blanks to filter data points in cluster 1 with feature > 5.
ML Python
filtered = [x for x, label in zip(X, labels) if label == [1] and x[[2]] [3] 5]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cluster label number.
Using wrong feature index.
Using '<' instead of '>' for filtering.
✗ Incorrect
We select points where cluster label is 1 and the first feature (index 0) is greater than 5.