Unsupervised Learning & Dimensionality Reduction

Finding Hidden Structure Without Labels

Not all data comes with labels. **Netflix** doesn't always know *why* a user watches a particular show—but it can discover hidden groups of similar users through **Clustering**. For **Visa**, the challenge is different: with hundreds of transaction features, **Dimensionality Reduction (PCA)** compresses the data into its most essential components without losing signal.

In this chapter, we explore **K-Means Clustering** for user segmentation, **PCA** for feature compression, and **Anomaly Detection** for catching outliers that don't belong to any cluster.

K-Means Clustering: User Segmentation

**K-Means** groups data points into **K** clusters by minimizing the distance between each point and its cluster center (centroid). For **Netflix**, this means grouping millions of users into "taste communities" (e.g., "Action Lovers," "Documentary Enthusiasts") without ever asking them to label themselves.

PythonRuns entirely in your browser — nothing is sent to a server.

PCA: Compressing Complex Data

**Principal Component Analysis (PCA)** finds the directions of maximum variance in your data and projects it onto fewer dimensions. For **Visa**, a transaction might have 200 features (time, location, merchant type, etc.). PCA can compress these into 10-20 "principal components" that capture 95% of the information, making models faster and more robust.

PythonRuns entirely in your browser — nothing is sent to a server.

Anomaly Detection: The Outlier Hunter

Anomaly Detection finds data points that don't belong to any cluster. For **Visa**, this is a second line of defense: even if a transaction passes rule-based checks, an anomaly detector can flag it as statistically "weird" compared to the user's typical behavior.

PythonRuns entirely in your browser — nothing is sent to a server.

Practice Questions

Question 1

Why is K-Means called 'unsupervised'?

  • Because the algorithm runs without electricity
  • Because it discovers groups in the data without needing pre-labeled examples
  • Because it only works at night
  • Because it requires a human supervisor to run

Question 2

What problem does PCA solve for Visa's 200-feature transaction data?

  • It makes the data look prettier
  • It reduces the number of features while preserving most of the important variance, making models faster and less prone to overfitting
  • It adds more features to improve accuracy
  • It encrypts the data for security