Scalable Analytics: Chapter 4
Fundamentals of Clustering in High-Dimensional Space
The Definition and Problem of Clustering
Clustering involves taking a set of points and a notion of distance between them to group the points into a specific number of clusters.
While clustering is straightforward in two dimensions or for small datasets, it becomes difficult in high-dimensional spaces (e.g., 10 to 10,000 dimensions).
High-dimensional spaces exhibit unique characteristics: almost all pairs of points are located at approximately the same distance from one another.
Practical Applications of Clustering
Wind Farm Management: Clustering is used for the optimal control of wind farms by grouping similar turbines based on operational parameters like rotor speed and power production.
Galactic Catalogs: In astronomy, a catalog of 2 billion "sky objects" represents items by their radiation across 7 dimensions. The goal is to cluster these into distinct objects such as galaxies, quasars, or nearby stars.
Distance Measures
Similarity is defined by the type of data being analyzed:
Vectors: Similarity is measured by the cosine distance.
Sets: Similarity is measured by the Jaccard distance.
Points: Similarity is measured by Euclidean distance.
K-Means Clustering
Core Principles and Euclidean Space
k-means assumes the data exists in Euclidean space and utilizes Euclidean distance.
Input: A dataset , where each .
Objective: Find a set of clusters where , with the intersections of clusters being empty () and the union of clusters representing the entire dataset ().
Distance Function and Metric Properties
The distance function must satisfy the following metric properties:
Symmetry:
Triangle Inequality:
Common metrics used include Euclidean distance and Manhattan distance.
Optimization and Heuristics
The k-means problem is defined as:
This problem is NP-hard. It is typically solved using Lloyd's algorithm, a heuristic approach.
Determining the Value of k
To find the optimal number of clusters, one can try different values of and observe the change in the average distance to the centroid.
Elbow Method: The average distance falls rapidly until the "right" is reached, after which it changes little. The ideal is located at this "elbow" in the plot.
The BFR (Bradley-Fayyad-Reina) Algorithm
Extension for Big Data
BFR is a variant of k-means designed to handle massive, disk-resident datasets.
It assumes clusters are normally distributed around a centroid in Euclidean space.
The algorithm operates by keeping summary statistics of groups of points rather than keeping the points themselves in memory.
Point Classification in BFR
BFR tracks three distinct sets of points:
Discard Set (DS): Points close enough to a centroid to be summarized.
Compression Set (CS): Groups of points that are close to each other but not close to any existing centroid.
Retained Set (RS): Isolated points waiting to be assigned to a compression set or discarded.
Summarizing Sets of Points
For each cluster, the Discard Set is summarized by three values ( values represent a cluster of any size in dimensions):
N: The total number of points.
SUM: A vector where the -th component is the sum of the coordinates in the -th dimension.
SUMSQ: A vector where the -th component is the sum of the squares of the coordinates in the -th dimension.
From these summary statistics, the following can be calculated:
Centroid (Average in dimension i):
Variance in dimension i:
Algorithm Workflow
Initialize clusters/centroids (e.g., via random points or optimal clustering of a small sample).
Load a bag of points from disk.
Assign new points to one of the clusters if they are "sufficiently close."
Cluster the remaining points into new compression sets () or add to the retained set ().
Attempt to merge new compression sets with existing ones if the combined variance is below a threshold.
Adjust cluster statistics for the new points.
Repeat until all points are examined; in the final round, merge all and points into their nearest cluster.
Mahalanobis Distance
To decide if a point is "close enough" to a cluster, BFR uses the Mahalanobis distance, which is a normalized Euclidean distance:
Normalize the point in each dimension:
Take the sum of the squares of the .
Take the square root:
If clusters are normally distributed in dimensions, one standard deviation equals .
A point is typically accepted if its Mahalanobis distance is below a threshold, such as 2 standard deviations.
The CURE (Clustering Using REpresentatives) Algorithm
Handling Arbitrary Shapes
K-means and BFR assume clusters are normally distributed in each dimension and aligned with fixed axes. They cannot handle clusters of arbitrary shapes (e.g., concentric rings).
CURE assumes Euclidean distance but allows for any cluster shape.
Instead of one centroid, CURE uses a collection of representative points to represent each cluster.
CURE Two-Pass Approach
Pass 1: Initialization
Pick a random sample of points that fit in main memory.
Cluster these points hierarchically to find initial clusters.
Pick representative points for each cluster: select a sample of dispersed points and move them slightly toward the cluster centroid.
Pass 2: Completion
Rescan the entire dataset.
Visit each point and place it in the cluster of the closest representative point.
Dimensionality Reduction
Concepts and Goals
Dimensionality reduction assumes data lies on or near a low d-dimensional subspace.
Goals:
Discover hidden correlations or topics.
Remove redundant and noisy features.
Improve interpretation and visualization.
Facilitate easier storage and processing.
Rank: The number of linearly independent rows in a matrix. Low-rank matrices allow data to be rewritten using basis vectors and new coordinates.
Singular Value Decomposition (SVD)
Definition
SVD decomposes an input data matrix into:
U: Left singular vectors (User-to-concept similarity matrix).
: Diagonal matrix of singular values representing the "strength" of each concept. Values are positive and sorted ().
V: Right singular vectors (Movie-to-concept similarity matrix).
Properties
and are column orthonormal: and .
SVD always exists for any real matrix.
Practical Case Study: Movie Recommendations
In a users-to-movies matrix, concepts (latent dimensions/factors) might represent genres like 'SciFi' or 'Romance.'
Querying: To find users that like a movie (e.g., 'Matrix'), the query is mapped into concept space: .
This allows finding similarities between users even if they have zero common ratings, provided they share similar concept preferences.
Drawbacks and Complexity
Drawbacks: Interpretability is difficult; concepts can be hard to define. Singular vectors are usually dense (lack of sparsity).
Complexity: Generally or . It is implemented in packages like LINPACK, Matlab, and Mathematica.
Scalable SVD for Large Sparse Matrices
The Challenge of Tall and Skinny Matrices
In scenarios like Twitter (user similarity) or Netflix (users vs movies), the matrix is often (e.g., rows vs columns).
These matrices are sparse, with each row having at most non-zeros (e.g., ).
Naive MapReduce Approach
One can approximate SVD by computing .
Naive computation involves all dot products:
Shuffle size: .
Reduce-key complexity: .
DIMSUM Importance Sampling
To scale higher, importance sampling is used. A random matrix is generated such that its entries approximate the cosine similarities between columns of .
DIMSUM Mapper: For all pairs of non-zero entries in row , emit the product with probability:
is a parameter to modulate behavior:
Low : Preserves similar entries of .
High : Preserves singular values.
DIMSUM Reducer: Approximates the expectation to output the entry .
Complexity and Guarantees
Shuffle size: .
Reduce-key complexity: .
Using Probably Approximately Correct (PAC) guarantees, is chosen based on whether the goal is preserving similarities or singular values.