Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 4

Introduction to Unsupervised Learning

Recommended resources

Introduction

Welcome to your fourth lesson in the "Core Concepts of Artificial Intelligence" module. In our last session, we detailed the process of supervised learning, where an AI learns from data that has been labeled with a correct "answer key." We examined the workflow from data splitting to model training and the critical importance of evaluation.

This lesson addresses the flip side of that coin, where no answer key is provided. Our learning outcome is to describe the primary goals of unsupervised learning, with examples such as clustering and anomaly detection. We will explore how algorithms can discover hidden patterns and structures within unlabeled data.

Understanding this paradigm is essential for a career in AI governance. Unsupervised techniques power systems for customer segmentation, fraud detection, and network security monitoring. The patterns they "discover" can have significant legal implications, from raising questions of discriminatory profiling in marketing to forming the basis of evidence in financial crime investigations. Your experience with data analytics and Python will be valuable as we explore the mechanics of these methods.


1. Learning Without an Answer Key

The fundamental difference between supervised and unsupervised learning lies in the data. While supervised learning relies on labeled data (e.g., emails marked as spam or not spam), unsupervised learning works with unlabeled data. The goal is not to predict a known output, but to explore the data's intrinsic structure.

Unsupervised Learning | Unsupervised Learning Algorithms | Machine Learning Tutorial | Simplilearn

To begin, let's watch a short segment from the Simplilearn video 'Unsupervised Learning' which clearly explains this distinction and introduces the core idea.

Watch the clip from 00:08 to 02:00. Focus on the contrast between supervised and unsupervised learning and how the algorithm must act on the data without guidance.

As the video explained, without predefined labels, the algorithm's task shifts from prediction to discovery. It sifts through the data to find natural groupings, unusual data points, or underlying rules. The two most common goals of this discovery process are clustering and anomaly detection.


2. The Goal of Clustering: Finding Natural Groups

Clustering is the process of grouping a set of data points such that points in the same group (called a cluster) are more similar to each other than to those in other clusters. The algorithm doesn't know what the clusters represent beforehand; it simply identifies them based on the mathematical properties of the data.

The purpose of clustering is to segment a dataset into meaningful subgroups. This is directly relevant to your consulting background, where you might have encountered tasks like:

  • Customer Segmentation: Grouping customers based on purchasing behavior to create targeted marketing campaigns.
  • Document Analysis: Grouping thousands of legal documents by topic for e-discovery.
  • Image Segmentation: Grouping pixels in an image to identify distinct objects.

Let's explore two common clustering approaches.

An Uncomplicated Guide to Unsupervised Machine Learning

The article 'An Uncomplicated Guide to Unsupervised Machine Learning' provides excellent, concise explanations of K-Means and Hierarchical clustering.

Please read the 'Clustering' section, including the subsections on the 'KMeans Algorithm' and 'Hierarchical Clustering'. Pay close attention to the visual explanations (the GIF for K-Means and the dendrogram for Hierarchical clustering) as they provide great intuition for how these algorithms work.

Key Clustering Algorithms

As you read in the article, the two main types of clustering are:

  1. K-Means Clustering: This is a partitional algorithm. You start by specifying the number of clusters, K. The algorithm then iteratively assigns each data point to the nearest cluster center (centroid) and recalculates the centroid's position based on the mean of the points assigned to it. It repeats this process until the centroids no longer move significantly. The main challenge is determining the optimal value for K beforehand.

  2. Hierarchical Clustering: This algorithm creates a tree-like hierarchy of clusters called a dendrogram.

    • Agglomerative (bottom-up): Starts with each data point as its own cluster and progressively merges the closest pairs of clusters.
    • Divisive (top-down): Starts with all data points in one cluster and recursively splits them.
      The dendrogram allows you to visualize the groupings at different levels of similarity and choose the number of clusters after the algorithm has run by setting a "cutoff" point.

3. The Goal of Anomaly Detection: Identifying the Unusual

Anomaly detection (or outlier detection) is the task of identifying data points, events, or observations that deviate significantly from the expected pattern of a dataset. These "anomalies" are often the most critical pieces of data.

From a legal and governance perspective, this is an extremely important AI capability. Consider its applications:

  • Fraud Detection: Identifying unusual credit card transactions that don't match a user's spending habits.
  • Cybersecurity: Detecting abnormal network traffic that could signal an intrusion or data breach.
  • Healthcare: Spotting anomalous readings from a patient's vital signs that may indicate a critical health event.

Anomalies are, by definition, rare. This makes it difficult to use supervised learning, as you often don't have enough labeled examples of "anomalous" behavior to train a model effectively. Unsupervised methods solve this by learning what "normal" looks like and flagging anything that falls outside that norm.

Techniques for Anomaly Detection

Several unsupervised algorithms can be used for this purpose. Given your interest in a technical deep-dive, we'll explore the intuition behind three powerful methods.

Complete Anomaly Detection Tutorials Machine Learning And Its Types With Implementation | Krish Naik

The video 'Complete Anomaly Detection Tutorials' by Krish Naik provides an excellent technical breakdown of several key algorithms. It's a great resource for understanding how these methods work under the hood.

Please watch the following three segments from the video: Introduction (00:00 - 02:47): This explains what an anomaly is with practical examples like bank security and medical diagnosis. Isolation Forest (03:42 - 16:33): This is a detailed explanation. Pay close attention to the core idea that anomalies are 'easier to isolate' and the mathematical intuition behind the anomaly score. You don't need to memorize the formula, but understand how path length in the decision tree relates to the anomaly score. DB-Scan for Anomalies (22:00 - 26:40): This segment explains how a density-based clustering algorithm like DB-Scan can be used for anomaly detection. It defines core points, border points, and noise/outliers, where 'noise' points are our anomalies. This provides a neat link back to our topic of clustering.

Let's summarize the key techniques you just saw:

  1. Isolation Forest: This algorithm is built on the idea that anomalies are "few and different," making them easier to isolate than normal points. It builds a "forest" of random decision trees. Anomalous points, being outliers, will require fewer random splits to be isolated into their own leaf node. The algorithm calculates an anomaly score based on the average path length required to isolate a point across all trees. A shorter average path results in a higher anomaly score.

  2. DBSCAN (Density-Based Spatial Clustering of Applications with Noise): As we saw, this clustering algorithm can also be used for anomaly detection. It groups together points that are closely packed, marking points that lie alone in low-density regions as "noise." These noise points are, by definition, outliers or anomalies.

  3. Local Outlier Factor (LOF): The video also briefly introduced this concept. LOF is a powerful algorithm that computes an anomaly score by comparing the local density of a data point to the local densities of its neighbors. This allows it to identify anomalies that might be outliers within a specific local region, even if they wouldn't appear as a "global" outlier. For example, a slightly unusual transaction might be normal for a high-spending customer but anomalous for a frugal one. LOF can capture this context.

Test your understanding!

A city's transportation authority collects massive amounts of data from its public transit system. They want to use machine learning to achieve two goals:

  1. Identify distinct groups of commuters with similar travel patterns (e.g., "9-to-5 downtown workers," "weekend shoppers," "late-night service workers") to better plan routes and schedules.
  2. Detect unusual events in real-time, such as a sudden, inexplicable drop in passenger taps at a major station, which could indicate an equipment failure or a public safety incident.

For each goal, state whether it is a clustering or an anomaly detection task and briefly justify your choice.

Show answer
  1. Goal 1 is a clustering task. The objective is to segment the entire population of commuters into distinct groups based on similarities in their travel data (time, location, frequency). The system is not looking for a single "abnormal" event but rather for the underlying structure and natural groupings within the whole dataset.

  2. Goal 2 is an anomaly detection task. The objective is to identify rare events that deviate significantly from the normal, expected pattern of passenger flow. The system would learn the baseline "normal" for each station at different times and flag any significant departure from that baseline as an anomaly requiring investigation.


Conclusion

In this lesson, we ventured into the world of unsupervised learning, where algorithms work without an answer key to find hidden structures in data.

Key Takeaways:

  • Unsupervised learning operates on unlabeled data with the primary goal of pattern discovery.
  • Clustering is the task of grouping similar data points. Algorithms like K-Means and Hierarchical Clustering are used to segment data for purposes like market analysis or document organization.
  • Anomaly Detection is the task of identifying rare outliers that deviate from the norm. Techniques like Isolation Forest and DBSCAN are critical for applications in fraud detection, cybersecurity, and system monitoring.

These techniques, while powerful, carry significant governance challenges. Clustering can inadvertently lead to redlining or discriminatory profiling if used without care. Anomaly detection used for surveillance can infringe on privacy rights and may be prone to errors that unfairly single out individuals. As a future legal expert in this domain, your ability to understand how these systems work is the first step toward crafting fair and effective regulations.

Preview of the Next Lesson:
We have now covered supervised learning (learning with labels) and unsupervised learning (learning without labels). In our final lesson of this module, we will explore the third major paradigm: Reinforcement Learning. You will learn about the core loop of an agent interacting with an environment, taking actions, and learning from a system of rewards and penalties—the foundation for training AIs to play games, control robots, and optimize complex systems.