0
0
SciPydata~10 mins

Flat clustering (fcluster) 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 flat clustering from scipy.

SciPy
from scipy.cluster.hierarchy import [1]
Drag options to blanks, or click blank then click option'
Alinkage
Bward
Cfcluster
Ddendrogram
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'linkage' instead of 'fcluster'.
Confusing 'dendrogram' with 'fcluster'.
2fill in blank
medium

Complete the code to create flat clusters using a distance threshold of 1.5.

SciPy
clusters = fcluster(linkage_matrix, [1], criterion='distance')
Drag options to blanks, or click blank then click option'
A3.0
B2.0
C0.5
D1.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a threshold other than 1.5.
Confusing the threshold with the number of clusters.
3fill in blank
hard

Fix the error in the code to correctly assign clusters by maximum number of clusters = 3.

SciPy
clusters = fcluster(linkage_matrix, [1], criterion='maxclust')
Drag options to blanks, or click blank then click option'
A3
B2
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a threshold that does not match the desired number of clusters.
Confusing 'distance' criterion with 'maxclust'.
4fill in blank
hard

Fill both blanks to create a dictionary of cluster labels and their counts.

SciPy
cluster_counts = {label: [1] for label in set(clusters) if clusters.count(label) [2] 1}
Drag options to blanks, or click blank then click option'
Aclusters.count(label)
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' in the condition.
Using a wrong method to count occurrences.
5fill in blank
hard

Fill all three blanks to create a list of cluster labels for points with distance less than 2.0.

SciPy
selected_clusters = [[1] for i, d in enumerate(distances) if d [2] [3]]
Drag options to blanks, or click blank then click option'
Aclusters[i]
B<
C2.0
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in the condition.
Using 'd' instead of 'clusters[i]' in the output.