0
0
SciPydata~10 mins

K-means via scipy vs scikit-learn - Interactive Practice

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

Complete the code to import the KMeans class from scikit-learn.

SciPy
from sklearn.cluster import [1]
Drag options to blanks, or click blank then click option'
AKmean
BKMeans
Ckmeans
DCluster
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'kmeans' which is not recognized.
Misspelling the class name.
2fill in blank
medium

Complete the code to run K-means clustering with 3 clusters using scikit-learn.

SciPy
model = KMeans(n_clusters=[1])
model.fit(data)
Drag options to blanks, or click blank then click option'
A3
B0
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting n_clusters to 0 or 1 which is invalid or trivial.
Using a number different from the intended cluster count.
3fill in blank
hard

Fix the error in the code to compute K-means using scipy's kmeans function.

SciPy
from scipy.cluster.vq import kmeans
centroids, distortion = kmeans(data, [1])
Drag options to blanks, or click blank then click option'
A[3]
B'3'
C(3,)
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the number as a string like '3'.
Passing the number inside a list or tuple.
4fill in blank
hard

Fill both blanks to create a dictionary of cluster labels and their counts using scikit-learn.

SciPy
labels = model.[1]
counts = {label: list(labels).[2](label) for label in set(labels)}
Drag options to blanks, or click blank then click option'
Alabels_
Bcount
Dlabel_
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'labels' instead of 'labels_' attribute.
Using 'count' as a variable instead of a method.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.

SciPy
result = {word:: len(word) for word in words if len(word) [1] 3 and word [2] 'data'}
Drag options to blanks, or click blank then click option'
A:
B>
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in dictionary comprehension.
Using '==' instead of '!=' to exclude 'data'.