Module 11: Clustering - Participation Exercises#
Exercise 11.1: Prediction - How Many Clusters?#
Type: 🔮 Prediction (3 min)
You have process data from a reactor that operates in three known modes: startup, steady-state, and shutdown. You apply k-means.
Predict: Will k-means with k=3 find clusters that match the three operating modes?
Yes, definitely
Probably, if the modes are well-separated
Probably not, clusters aren’t always meaningful
No, k-means can’t find interpretable clusters
Explain your reasoning.
Your prediction and reasoning:
Exercise 11.2: Mini-Exercise - Scaling Impact#
Type: 🔧 Mini-Exercise (6 min)
See how scaling affects k-means clustering.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
# Two features with very different scales
np.random.seed(42)
n = 100
# Temperature (300-500 K) and pressure (1-10 atm)
# Two natural clusters based on pressure
cluster1 = np.column_stack([
np.random.normal(400, 30, n//2), # temperature
np.random.normal(3, 0.5, n//2) # pressure
])
cluster2 = np.column_stack([
np.random.normal(400, 30, n//2), # temperature
np.random.normal(7, 0.5, n//2) # pressure
])
X = np.vstack([cluster1, cluster2])
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
# Without scaling
kmeans_unscaled = KMeans(n_clusters=2, random_state=42, n_init=10)
labels_unscaled = kmeans_unscaled.fit_predict(X)
axes[0].scatter(X[:, 0], X[:, 1], c=labels_unscaled, cmap='viridis')
axes[0].set_xlabel('Temperature (K)')
axes[0].set_ylabel('Pressure (atm)')
axes[0].set_title('K-means WITHOUT scaling')
# With scaling
X_scaled = StandardScaler().fit_transform(X)
kmeans_scaled = KMeans(n_clusters=2, random_state=42, n_init=10)
labels_scaled = kmeans_scaled.fit_predict(X_scaled)
axes[1].scatter(X[:, 0], X[:, 1], c=labels_scaled, cmap='viridis')
axes[1].set_xlabel('Temperature (K)')
axes[1].set_ylabel('Pressure (atm)')
axes[1].set_title('K-means WITH scaling')
plt.tight_layout()
plt.show()
# TASK: Explain the difference. Which clustering is "correct"?
Your explanation:
Exercise 11.3: Discussion - Clustering Without Ground Truth#
Type: 💬 Discussion (5 min)
Clustering is unsupervised - there are no labels to tell us if we’re right.
Discuss:
How do you validate clusters without ground truth?
When might silhouette score be misleading?
What role does domain expertise play in evaluating clusters?
Discussion notes: