Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the KMeans class from scikit-learn.
ML Python
from sklearn.cluster import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
2fill in blank
mediumComplete the code to fit a KMeans model with 3 clusters on data X.
ML Python
model = KMeans(n_clusters=[1])
model.fit(X) Drag options to blanks, or click blank then click option'
Attempts:
3 left
3fill in blank
hardFix the error in the code to compute the silhouette score for clustering labels.
ML Python
from sklearn.metrics import silhouette_score score = silhouette_score(X, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
4fill in blank
hardFill both blanks to create a list of inertia values for K from 1 to 5.
ML Python
inertia_values = [] for k in range(1, 6): model = KMeans(n_clusters=[1]) model.fit(X) inertia_values.append([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
5fill in blank
hardFill all three blanks to compute silhouette scores for K from 2 to 6 and store them in a dictionary.
ML Python
silhouette_scores = {}
for k in range(2, 7):
model = KMeans(n_clusters=[1])
labels = model.fit_predict(X)
silhouette_scores[[2]] = [3](X, labels) Drag options to blanks, or click blank then click option'
Attempts:
3 left