Complete the code to import the KMeans class from scikit-learn.
from sklearn.cluster import [1]
The correct class name to import for K-means clustering in scikit-learn is KMeans with capital K and M.
Complete the code to run K-means clustering with 3 clusters using scikit-learn.
model = KMeans(n_clusters=[1])
model.fit(data)To cluster data into 3 groups, set n_clusters=3.
Fix the error in the code to compute K-means using scipy's kmeans function.
from scipy.cluster.vq import kmeans centroids, distortion = kmeans(data, [1])
The kmeans function expects the number of clusters as an integer, not a string or list.
Fill both blanks to create a dictionary of cluster labels and their counts using scikit-learn.
labels = model.[1] counts = {label: list(labels).[2](label) for label in set(labels)}
In scikit-learn, cluster labels are accessed with labels_. To count occurrences, use the list method count.
Fill both blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.
result = {word:: len(word) for word in words if len(word) [1] 3 and word [2] 'data'}The dictionary comprehension syntax uses ':' between key and value. We check if length is greater than 3 and word is not equal to 'data'.