Lesson 7 of 8Article18 min
Unsupervised Learning
Unsupervised Learning
Unsupervised learning objectives
- Clustering similar observations.
- Reducing dimensions for visualization and denoising.
- Detecting anomalies without labels.
K-means clustering
Cluster data into groups
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3, random_state=42, n_init=10)
labels = kmeans.fit_predict(X)
centroids = kmeans.cluster_centers_
print("Centroids shape:", centroids.shape)