Dimensionality Reduction interview question

Preprocessing & Feature EngineeringDimensionality ReductionText Featuresmedium

A bank vectorizes 2 million support tickets with TF-IDF over a 500,000-term vocabulary; the sparse matrix has about 100 non-zeros per row (≈ 2.4 GB in CSR format). For 300-dimensional latent semantic analysis (LSA), why is TruncatedSVD the standard choice rather than classic PCA?

  1. AClassic PCA centers each column, so every zero becomes minus its column mean and the 2M × 500k matrix turns dense; TruncatedSVD skips centering and works on the sparse matrix directly.
  2. BTF-IDF rows are already L2-normalized, so the data counts as centered and both methods return the same components; TruncatedSVD is just a faster solver for that identical PCA result.
  3. CClassic PCA has to invert the 500,000 × 500,000 covariance matrix, which is singular for text; TruncatedSVD avoids any matrix inversion by factorizing the rows of the matrix one at a time.
  4. DTruncatedSVD first scales every term column to unit variance so that rare terms are not drowned out by common ones, a rescaling that PCA cannot apply to a sparse text matrix.
Show the answer and explanation

Correct answer: A, Classic PCA centers each column, so every zero becomes minus its column mean and the 2M × 500k matrix turns dense; TruncatedSVD skips centering and works on the sparse matrix directly.

Explanation Dimensionality Reduction

PCA is the SVD of the column-centered data. Centering subtracts each term's mean TF-IDF weight from every row. Every term in a vocabulary learned from the tickets occurs at least once, so every column mean is positive and the ≈ 10¹² zero cells all become small negative numbers. Dense storage would need 2,000,000 × 500,000 × 8 bytes ≈ 8 TB, versus about 2.4 GB for the sparse matrix (≈ 2 × 10⁸ non-zeros × 12 bytes for values and column indices).

TruncatedSVD computes the top-k singular vectors of the uncentered matrix with randomized or ARPACK solvers that only need sparse matrix products, so memory grows with the non-zeros and the k-dimensional factors, not with the dense grid. On term-document matrices this is latent semantic analysis (LSA).

Consequences of skipping centering:

  • The result differs from PCA: the first component largely follows the average TF-IDF profile rather than a contrast between topics.
  • The output is often L2-normalized again (Normalizer) before cosine-based clustering or retrieval.

Why the other explanations fail: L2-normalizing rows gives each document unit length but does not make column means zero. PCA never inverts the covariance matrix; it eigendecomposes it or runs an SVD of the data. TruncatedSVD does not standardize columns; IDF weighting is what down-weights common terms.

Recent scikit-learn versions (1.4+) also accept sparse input in PCA with the arpack solver, centering implicitly without forming the dense matrix, but TruncatedSVD remains the standard LSA tool.

Interview tip: add that dense sentence embeddings usually capture meaning better than LSA, while TF-IDF + TruncatedSVD stays a cheap, explainable baseline for clustering and search.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Preprocessing & Feature Engineering questions

  1. A retailer's store_id has 1,000 levels. Instead of one-hot encoding, a colleague proposes binary encoding: give each store an integer code and write that code…
  2. Your features include age (years), income (TRY) and num_logins (count), on very different scales. For which group of models is feature scaling generally…
  3. A gradient-boosted house-price model for Istanbul uses raw latitude and longitude as features. Prices are highest around a few prime districts and along the…
  4. How do MCAR, MAR and MNAR differ in what the probability of a value being missing depends on?
  5. What does one-hot encoding do to a categorical feature such as color with the values red, green and blue?