When using the elbow method to choose the number of clusters K in K-means clustering, what does the 'elbow' point represent?
Think about when adding more clusters stops giving much better grouping.
The elbow point is where the decrease in WCSS slows down, indicating that adding more clusters beyond this point does not improve clustering significantly.
What does a silhouette score close to 1 indicate about the clustering quality?
Higher silhouette scores mean better clustering.
A silhouette score near 1 means each point is much closer to its own cluster than to others, indicating good clustering.
What is the output of the following Python code snippet?
from sklearn.datasets import make_blobs from sklearn.cluster import KMeans from sklearn.metrics import silhouette_score X, _ = make_blobs(n_samples=100, centers=3, cluster_std=0.5, random_state=42) model = KMeans(n_clusters=3, random_state=42) labels = model.fit_predict(X) score = silhouette_score(X, labels) print(round(score, 2))
The data has 3 clear clusters with low spread.
The silhouette score is high (~0.75) because the clusters are well separated and compact.
You run K-means clustering for K values from 2 to 6 and get these silhouette scores: {2: 0.45, 3: 0.62, 4: 0.58, 5: 0.55, 6: 0.50}. Which K should you choose based on silhouette score?
Pick the K with the highest silhouette score.
K=3 has the highest silhouette score (0.62), indicating the best cluster separation and cohesion.
What error will this code raise when trying to plot the elbow curve?
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
X, _ = make_blobs(n_samples=100, centers=4, random_state=0)
wcss = []
for k in range(1, 6):
model = KMeans(n_clusters=k)
model.fit(X)
wcss.append(model.inertia_)
plt.plot(range(1, 6), wcss)
plt.xlabel('Number of clusters')
plt.ylabel('WCSS')
plt.title('Elbow Method')
plt.show()Check if all required imports and parameters are correct for recent sklearn versions.
The code runs without error and plots the elbow curve. The default n_init changed in newer sklearn but does not cause error here.
