Skip to content
AI.info

Unsupervised learning

Random Projections, Feature Agglomeration, and Compression

Compare random projections, feature agglomeration, hashing-style compression, and learned reduction for scalable preprocessing.

By the end you can

Analogy

Casting many shadows from a complex object

Screens placed at random angles catch a different shadow of the same detailed object each time. A collection of shadows can preserve enough relative geometry to compare objects without reconstructing every surface.

A handful of shadows preserves only approximate relations. The guarantee depends on target dimension, distribution, and tolerance, and rare task-specific directions may still disappear. There is a number for that cost. Chari and Pachter reach it through the Johnson–Lindenstrauss lemma: “preservation of pairwise distances with a margin of error of at most 20% for a modestly sized dataset of 10,000 cells would require at least 1,842 dimensions”. Two dimensions are not a small approximation of 1,842. They are a different object.

Randomness can preserve distance approximately without producing a human-readable axis.

Figure

The accuracy you demand moves the required dimension by three orders of magnitude; the number of points barely moves it at all.

A useful reduction with no fitted components to interpret

Take a corpus that exists and can be downloaded. RCV1-v2 is 804,414 Reuters newswire documents over 47,236 stemmed-word features and 103 Topic categories, described in a benchmark paper in 2004; scikit-learn ships it as fetch_rcv1 and reports the feature matrix as 0.16% non-zero. Pushing 47,236 sparse dimensions through a fixed random matrix costs no fitting pass, no covariance estimate and no second read of the data. Memory and transform time fall. What comes out has no loadings to narrate and no axis anyone can name. It can still be the right engineering choice. Dimensionality reduction does not always need to discover interpretable axes.

Compression can preserve useful geometry without learning semantic components.

Visual

Three scalable compression strategies

Compression strategies differ in what they preserve and whether the mapping is learned from data.

“Random matrix” is vaguer than the literature needs to be. The entries can be coin flips. Achlioptas proved in 2003 that the same guarantee survives when every entry is drawn from {-1, 0, +1} with probabilities 1/6, 2/3, 1/6. Two thirds of the matrix is then zero, and the projection reduces to additions and subtractions: “probability distribution (2) gives an additional threefold speedup as we only need to process a third of all attributes for each of the k coordinates”, in his own words. scikit-learn ships that setting in SparseRandomProjection as density=1/3. Its actual default is sparser still, the 1/sqrt(n_features) recommended in 2006.

FigureHierarchy · 4 levels
  • Random projection

    Multiply by a random matrix designed to preserve pairwise distances approximately.

    • Feature agglomeration

      Cluster similar features and replace each group with an aggregate.

      • Hashing or sketching

        Map many input coordinates into a fixed-size space with controlled collisions.

        • Learned reduction

          Fit PCA, factorization, autoencoder, or task-specific embedding from data.

A data-independent transform can be reproducible and useful even without semantic axes.

Key idea

Random projection is not anonymization

A linear map conceals original feature names. It does not establish a privacy guarantee, and the literature closes the point from both sides.

Start with the constructive side. There is a method that does obtain differential privacy from a Johnson-Lindenstrauss projection — but not from the projection. Its abstract gives the recipe: “Our method involves projecting each user's representation into a random, lower-dimensional space via a sparse Johnson-Lindenstrauss transform and then adding Gaussian noise to each entry of the lower-dimensional representation.” The guarantee lives in the noise term. The projection is the cheap part underneath it.

Now the attacking side. A distance-preserving perturbation can be inverted from a handful of known records. On a real 16-dimensional dataset, four known original tuples suffice to estimate an unknown one to under 7% error with probability above 0.8.

Regulators apply the same test. GDPR Recital 26 holds that data which has undergone pseudonymisation and could be re-attributed using additional information is still information on an identifiable natural person, and it directs that “all the means reasonably likely to be used” be considered. The Article 29 Data Protection Working Party had already said it in 2014: “Pseudonymisation reduces the linkability of a dataset with the original identity of a data subject; as such, it is a useful security measure but not a method of anonymisation.” Treat privacy as a separate threat model, with access controls, minimization, and formal methods where required.

Obscured coordinates are not automatically protected data.

Steps

Benchmark a scalable compression map

The test should reflect the relation and rare evidence that downstream systems need. Note that two of the five steps below are not measurements at all. They are settings you have to write down before you can compute anything: the tolerance eps, and the matrix or table you sampled.

FigureProcess · 5 steps
  1. 1. Define tolerance

    Set acceptable change in distance, neighborhood, retrieval, model quality, and rare-case recall.

  2. 2. Compare dimensions

    Fit or sample several target sizes under fixed seeds and budgets.

  3. 3. Test sparse behavior

    Measure memory, transform time, density, and collision or aggregation effects.

  4. 4. Inspect rare signals

    Verify that low-frequency features and minority slices survive sufficiently.

  5. 5. Version the map

    Store random matrix, seed, feature schema, grouping tree, and downstream compatibility.

Example

Compression choices in large systems

Different mappings fail in different ways. The clearest evidence comes from systems that published their numbers.

The hashing case is the most instructive, because the compression itself turned out to be free. A spam experiment published in 2009 covered 3.2 million emails from 433,167 users, 40 million unique tokens after tokenization, and a personalized feature space of about 16 trillion possible features. The team hashed all of it into 2^22 dimensions. At that table size the global classifier's error converged and “hash collisions have no impact on the classification error”; the hashed model matched the unhashed baseline. What the hashing bought was the per-user personalization that 16 trillion features had made infeasible: “Figure 2 shows that despite aggressive hashing, personalization results in a 30% spam reduction once the hash table is indexed by 22 bits.” A 2018 paper gives the tight account of when collisions stop being harmless.

  • Sparse text: RCV1-v2 is the benchmark to run this on. “Our text representation approach produced a set of 47,236 features (stemmed words)”, the 2004 paper reports, across 804,414 documents and 103 Topic categories, with the chronological LYRL2004 split fixing 23,149 training and 781,265 test documents and scikit-learn reporting the matrix as 0.16% non-zero. A random projection lowers that dimension without computing a dense covariance matrix, and retrieval quality is checked against the original vectors on a split anyone else can reproduce.
  • Genomics: feature agglomeration groups correlated measurements, but the compression target has to be honest about what distances cost. Chari and Pachter's 1,842 dimensions for 10,000 cells at a 20% margin is the standard a two-dimensional picture is failing to meet. Analysts should also inspect whether one rare biomarker was averaged into a broad block.
  • Streaming features: hashing into 2^22 dimensions held a fixed schema over 40 million tokens and about 16 trillion personalized features. Collisions cost no measurable classification error at that table size, and personalization returned a 30% spam reduction.
  • Privacy misconception: a random projection obscures coordinates but supplies no formal guarantee. Reaching one took added Gaussian noise on top of the sparse transform. Running the other way, an unknown record was recovered to under 7% error from four known tuples in 16 dimensions.
  • Reproducibility: fixing and versioning the random seed is necessary because a new projection defines a new feature space. The parameters that define it — density=1/3 against the 1/sqrt(n_features) default, the target dimension, the eps that justified it — belong in the artifact beside the matrix.

Comparison

Random projection and PCA

Both create linear lower-dimensional coordinates. They use different evidence and they promise different things.

PCA minimises average squared reconstruction error over the data it was fitted on. A Johnson-Lindenstrauss transform bounds worst-case pairwise distortion instead. And it is sampled from the source dimension, the number of vectors and the tolerance alone — never from the data. Freksen draws the practical consequence: “This allows us to sample a JLT without having access to the input data, e.g. to compute the JLT before the data exists, or to compute the JLT in settings where the data is too large to store on or move to a single machine”. That is why johnson_lindenstrauss_min_dim takes only n_samples and eps as arguments. There is no data matrix to hand it.

The dimension it demands is not slack in the proof that a cleverer sampled matrix could win back. Dasgupta and Gupta flagged the limit in their own introduction — “In recent work, Noga Alon has shown that this result is essentially tight” — and Larsen and Nelson closed the remaining gap in 2017. For any integers d, n >= 2 and any eps with 1/(min{n,d})^0.4999 < eps < 1, they exhibit a set of n vectors in R^d for which any embedding preserving all pairwise distances to within (1 +/- eps) must use m = Omega(eps^-2 lg n) dimensions. The eps^-2 log n price is a floor, not a first attempt.

FigureComparison · 3 columns

Random projection

Uses a sampled matrix independent of the observed covariance.

  • Requires no fitting pass
  • Scales to sparse high dimensions
  • Offers probabilistic distance preservation
  • Has weak component interpretability

PCA

Learns directions from the reference covariance structure.

  • Optimizes variance and reconstruction
  • Needs fitting and versioned means
  • Can denoise correlated features
  • May overfit reference-specific variance

Feature agglomeration

Clusters columns rather than rows.

  • Produces groups of related features
  • Can retain block interpretability
  • Depends on feature similarity and linkage
  • May merge variables with different causal roles

Interpretability has more than one form

PCA offers loadings, feature agglomeration offers groups, and random projection offers a simple reproducible mapping with geometric guarantees. The most interpretable method for an engineer may not be the most interpretable for a domain expert.

Choose reduction according to the evidence the system must preserve and explain. Record approximation error rather than treating lower dimension as an improvement by itself. The bound scikit-learn ships is not a rule of thumb. johnson_lindenstrauss_min_dim implements Theorem 2.1 of Dasgupta and Gupta, which fixes k >= 4(eps^2/2 - eps^3/3)^-1 ln n, and the library cites them by name. The User Guide states the contract: “Knowing only the number of samples, the johnson_lindenstrauss_min_dim estimates conservatively the minimal size of the random subspace to guarantee a bounded distortion introduced by the random projection”.

Then read what the formula returns. For one million points it gives 663 target dimensions at 50 percent tolerance, 11,841 at 10 percent and 1,112,658 at 1 percent. The library's own Gaussian example is smaller and no kinder: a 100-row, 10,000-column matrix at the default eps=0.1 projects to 3,947 components. The bound moves with the number of points and the tolerance, never with the original dimension. And because it is conservative, it is the ceiling to argue down from with measurements, not a number to quietly ignore.

Compression is successful when declared relationships survive at lower cost.

Key takeaways