liveBook · Manning

Singular value decomposition

As explained in Data Without Labels

Singular value decomposition is a matrix factorization that expresses a matrix as the product of two orthogonal matrices and a diagonal matrix of singular values.

A dataset with many variables can be difficult to visualize and costly to analyze. Singular value decomposition (SVD) reduces dimensions by representing a data matrix through singular vectors and singular values. Like principal component analysis (PCA), it supports a transformation to fewer dimensions, but SVD can factorize a matrix with any number of rows and columns. section 3.0 section 3.6

(3.3)

A = U * S * VT

The factorization writes the original matrix A as U × S × Vᵀ. U and V contain orthonormal singular vectors; the diagonal matrix S holds the singular values. The vectors come from the square matrices AAᵀ and AᵀA, and the singular values are square roots of their eigenvalues. section 3.6

A practical Python workflow is:

  • Inspect and clean the data. Convert categorical features to numeric values, separate features from any class label, and standardize the features. section 3.6.1 section 3.8
  • Run `u, s, v = np.linalg.svd(X_features, full_matrices=True)`. Inspect the outputs: `s` contains singular values, while `u` and `v` contain singular vectors. section 3.6.1
  • Calculate each displayed variance share as `s**2 / np.sum(s**2)`. Plot the shares to judge how many components to retain, then inspect a scatter plot using the selected components. section 3.6.1

Exploring mushroom classes

Encode the mushroom dataset’s categorical columns, standardize its feature columns, and run NumPy’s SVD. A bar plot compares the variance shares; a scatter plot places the first two plotted singular vectors on its axes and colors observations as edible or poisonous. Two axes make the data easier to inspect, but check the variance plot before deciding that two components are enough. section 3.6.1

Reduced dimensions can make visualization easier and lower training time; reducing correlated variables may also help model accuracy and overfitting. The trade-offs are possible information loss and components that are harder to relate to real-world attributes. SVD requires numeric, standardized input. For a telecommunications dataset combining demographics, subscriptions, usage, and payments, first check missing values, duplicates, and uninformative variables before reducing dimensions for later analysis. section 3.7 section 3.8

How Data Without Labels covers it

How deep it goes
Defines the factorization, relates singular vectors to eigenvectors, and works through Python preparation and plots; defers mathematical proofs.
Examples
Uses encoded mushroom data, variance and class-colored plots, and a high-dimensional telecommunications subscriber scenario.
What it assumes
Assumes familiarity with Python data preparation; introduces the matrix factorization while requiring numeric encoding and standardization before application.
What you can do after
Apply it via NumPy to standardized numeric features and inspect singular-value variance shares and component plots.
How it connects
Connects SVD to PCA, eigenvalue decomposition, dimensionality reduction, and clustering.

Also explained in

Compare how 6 books explain singular value decomposition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Without Labels. The section links point to the parts of the book it draws on.