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 D={x1,…,xn}D = \{x_1, \dots, x_n\}, where each xi∈Rdx_i \in \mathbb{R}^d.

  • Objective: Find a set of clusters C={c1,…,ck}C = \{c_1, \dots, c_k\} where ci⊆Dc_i \subseteq D, with the intersections of clusters being empty (⋂i=1kci=∅\bigcap_{i=1}^k c_i = \emptyset) and the union of clusters representing the entire dataset (⋃i=1kci=D\bigcup_{i=1}^k c_i = D).

Distance Function and Metric Properties

The distance function d(xi,xj)→R+d(x_i, x_j) \rightarrow \mathbb{R}^+ must satisfy the following metric properties:

  1. d(xi,xj)=0  ⟺  xi=xjd(x_i, x_j) = 0 \iff x_i = x_j

  2. Symmetry: d(xi,xj)=d(xj,xi)d(x_i, x_j) = d(x_j, x_i)

  3. Triangle Inequality: d(xi,xj)≤d(xi,xk)+d(xk,xj)d(x_i, x_j) \leq d(x_i, x_k) + d(x_k, x_j)

  • Common metrics used include Euclidean distance and Manhattan distance.

Optimization and Heuristics
  • The k-means problem is defined as:     arg minC∑i=1k∑xj∈Ci∥xj−μi∥2\text{arg min}_{C} \sum_{i=1}^k \sum_{x_j \in C_i} \|x_j - \mu_i\|^2

  • 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 kk and observe the change in the average distance to the centroid.

  • Elbow Method: The average distance falls rapidly until the "right" kk is reached, after which it changes little. The ideal kk 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 (2d+12d + 1 values represent a cluster of any size in dd dimensions):

  1. N: The total number of points.

  2. SUM: A vector where the ii-th component is the sum of the coordinates in the ii-th dimension.

  3. SUMSQ: A vector where the ii-th component is the sum of the squares of the coordinates in the ii-th dimension.

From these summary statistics, the following can be calculated:

  • Centroid (Average in dimension i): SUMiN\frac{\text{SUM}_i}{N}

  • Variance in dimension i: SUMSQiN−(SUMiN)2\frac{\text{SUMSQ}_i}{N} - \left(\frac{\text{SUM}_i}{N}\right)^2

Algorithm Workflow
  1. Initialize KK clusters/centroids (e.g., via random points or optimal clustering of a small sample).

  2. Load a bag of points from disk.

  3. Assign new points to one of the KK clusters if they are "sufficiently close."

  4. Cluster the remaining points into new compression sets (CSCS) or add to the retained set (RSRS).

  5. Attempt to merge new compression sets with existing ones if the combined variance is below a threshold.

  6. Adjust cluster statistics for the new points.

  7. Repeat until all points are examined; in the final round, merge all CSCS and RSRS 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:

  1. Normalize the point in each dimension: yi=xi−ciσiy_i = \frac{x_i - c_i}{\sigma_i}

  2. Take the sum of the squares of the yiy_i.

  3. Take the square root: d(x,c)=∑i=1d(xi−ciσi)2d(x, c) = \sqrt{\sum_{i=1}^d \left(\frac{x_i - c_i}{\sigma_i}\right)^2}

  • If clusters are normally distributed in dd dimensions, one standard deviation equals d\sqrt{d}.

  • 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
  1. Pick a random sample of points that fit in main memory.

  2. Cluster these points hierarchically to find initial clusters.

  3. Pick representative points for each cluster: select a sample of dispersed points and move them slightly toward the cluster centroid.

Pass 2: Completion
  1. Rescan the entire dataset.

  2. Visit each point pp 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 A[m×n]A[m \times n] into: A[m×n]=U[m×r]Σ[r×r](V[n×r])TA[m \times n] = U[m \times r] \Sigma[r \times r] (V[n \times r])^T

  • U: Left singular vectors (User-to-concept similarity matrix).

  • Σ\Sigma: Diagonal matrix of singular values representing the "strength" of each concept. Values are positive and sorted (σ1≥σ2≥⋯≥0\sigma_1 \geq \sigma_2 \geq \dots \geq 0).

  • V: Right singular vectors (Movie-to-concept similarity matrix).

Properties
  • UU and VV are column orthonormal: UTU=IU^T U = I and VTV=IV^T V = I.

  • 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 qq is mapped into concept space: qconcept=qVq_{\text{concept}} = q V.

  • 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 O(nm2)O(nm^2) or O(n2m)O(n^2 m). 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 AA is often m≫nm \gg n (e.g., 101310^{13} rows vs 10410^4 columns).

  • These matrices are sparse, with each row having at most LL non-zeros (e.g., L=20L=20).

Naive MapReduce Approach
  • One can approximate SVD by computing ATA=VΣΣTVTA^T A = V \Sigma \Sigma^T V^T.

  • Naive computation involves all dot products:

    • Shuffle size: O(mL2)O(m L^2).

    • Reduce-key complexity: mm.

DIMSUM Importance Sampling
  • To scale higher, importance sampling is used. A random matrix BB is generated such that its entries approximate the cosine similarities between columns of AA.

  • DIMSUM Mapper: For all pairs of non-zero entries (aij,aik)(a_{ij}, a_{ik}) in row rir_i, emit the product with probability:     P=min⁡(1,γ∥cj∥∥ck∥)P = \min\left(1, \frac{\gamma}{\|c_j\| \|c_k\|}\right)

  • γ\gamma is a parameter to modulate behavior:

    • Low γ\gamma: Preserves similar entries of ATAA^T A.

    • High γ\gamma: Preserves singular values.

  • DIMSUM Reducer: Approximates the expectation to output the entry bjkb_{jk}.

Complexity and Guarantees
  • Shuffle size: O(n⋅L⋅γ)O(n \cdot L \cdot \gamma).

  • Reduce-key complexity: O(n⋅γ)O(n \cdot \gamma).

  • Using Probably Approximately Correct (PAC) guarantees, γ\gamma is chosen based on whether the goal is preserving similarities or singular values.