0
0
ML Pythonml~10 mins

Mean shift clustering in ML Python - 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 MeanShift class from scikit-learn.

ML Python
from sklearn.cluster import [1]
Drag options to blanks, or click blank then click option'
AMeanShift
BKMeans
CDBSCAN
DAgglomerativeClustering
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a different clustering class like KMeans or DBSCAN.
Misspelling the class name.
2fill in blank
medium

Complete the code to create a MeanShift object with default bandwidth.

ML Python
ms = MeanShift([1]=None)
Drag options to blanks, or click blank then click option'
Amax_iter
Brandom_state
Cn_clusters
Dbandwidth
Attempts:
3 left
💡 Hint
Common Mistakes
Using max_iter or n_clusters which are not parameters for bandwidth.
Setting random_state which is unrelated here.
3fill in blank
hard

Fix the error in the code to fit the MeanShift model on data X.

ML Python
ms = MeanShift()
ms.[1](X)
Drag options to blanks, or click blank then click option'
Apredict
Bfit
Ctransform
Dfit_predict
Attempts:
3 left
💡 Hint
Common Mistakes
Using predict before fitting the model.
Using transform which is not available for MeanShift.
4fill in blank
hard

Fill both blanks to get cluster labels and cluster centers from the fitted model.

ML Python
labels = ms.[1]
centers = ms.[2]
Drag options to blanks, or click blank then click option'
Alabels_
Bcluster_centers_
Cfit
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like fit or predict instead of attributes.
Confusing labels_ with cluster_centers_.
5fill in blank
hard

Fill all three blanks to compute the number of clusters and print it.

ML Python
n_clusters = len(set(ms.[1]))
print('Number of clusters:', [2])
print('Labels:', ms.[3])
Drag options to blanks, or click blank then click option'
Alabels_
Bn_clusters
Dcluster_centers_
Attempts:
3 left
💡 Hint
Common Mistakes
Using cluster_centers_ instead of labels_ to count clusters.
Printing wrong variables or attributes.