0
0
SciPydata~10 mins

Why clustering groups similar data in SciPy - Test Your Understanding

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

Complete the code to import the clustering function from scipy.

SciPy
from scipy.cluster import [1]
Drag options to blanks, or click blank then click option'
Acluster
Bhierarchy
Cspatial
Doptimize
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing unrelated modules like 'optimize' or 'spatial'.
Choosing 'cluster', the package containing the hierarchy module.
2fill in blank
medium

Complete the code to create a linkage matrix for clustering.

SciPy
linkage_matrix = hierarchy.[1](data, method='ward')
Drag options to blanks, or click blank then click option'
Alinkage
Bdendrogram
Ckmeans
Dfcluster
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dendrogram' which is for plotting, not creating linkage.
Using 'kmeans' which is a different clustering method.
3fill in blank
hard

Fix the error in the code to plot a dendrogram using the linkage matrix.

SciPy
hierarchy.[1](linkage_matrix)
plt.show()
Drag options to blanks, or click blank then click option'
Afcluster
Blinkage
Cdendrogram
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'linkage' which returns data, not a plot.
Using 'plot' which is not a scipy.cluster function.
4fill in blank
hard

Fill both blanks to create a dictionary of cluster labels for data points with distance threshold 5.

SciPy
labels = hierarchy.[1](linkage_matrix, t=[2], criterion='distance')
Drag options to blanks, or click blank then click option'
Afcluster
B3
C5
Dlinkage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'linkage' instead of 'fcluster' for flat clusters.
Choosing wrong threshold values like 3 instead of 5.
5fill in blank
hard

Fill the two blanks to create a dictionary of cluster sizes for clusters with labels greater than 1.

SciPy
cluster_sizes = {label: sum(labels == label) for label in set(labels) if label [1] [2] }
Drag options to blanks, or click blank then click option'
A1
B==
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' in the condition.
Using wrong label value like 0 instead of 1.