0
0
ML Pythonprogramming~10 mins

Choosing K (elbow method, silhouette score) in ML Python - 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 KMeans class from scikit-learn.

ML Python
from sklearn.cluster import [1]
Drag options to blanks, or click blank then click option'
ADecisionTreeClassifier
BLinearRegression
CPCA
DKMeans
Attempts:
3 left
2fill in blank
medium

Complete 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'
A3
B1
C10
D5
Attempts:
3 left
3fill in blank
hard

Fix 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'
Amodel.fit(X)
Bmodel.predict(X)
Cmodel.labels_
DX
Attempts:
3 left
4fill in blank
hard

Fill 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'
Ak
Bmodel.inertia_
Cmodel.score(X)
DX
Attempts:
3 left
5fill in blank
hard

Fill 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'
Ak
Csilhouette_score
Dmodel.inertia_
Attempts:
3 left