Skip to content

The SVD and the best low-rank copy of a table

Every matrix is a rotation, a stretch and another rotation. Use the singular value decomposition to compute PCA safely, keep the best rank-k copy of a table, and give PCA a likelihood with probabilistic PCA.

Applied ~14 min9 steps

What runs in CodeSplash

You will be able to

  • Write the SVD and connect its pieces to PCA directions, scores and eigenvalues
  • State the Eckart–Young result and compute the error of a rank-k approximation from the singular values
  • Explain what probabilistic PCA adds - a noise variance, a likelihood and a rank chosen by BIC

Read first

01

Rotate, stretch, rotate

Read

The singular value decompositionSingular value decompositionWrites any matrix as rotation × stretch × rotation, X = UΣVᵀ. It works for non-square matrices and is how PCA is computed. writes any n×pn \times p matrix as

X=UΣV⊤.X = U \Sigma V^\top .

VV turns the input space, the diagonal Σ\Sigma stretches each axis by a singular value σk\sigma_k, and UU places the result in the output space. Unlike the eigendecomposition, it works for any rectangular matrix.

For a centered data matrix: the columns of VV are the principal directions, UΣU\Sigma holds the scores, and σk2/(n−1)\sigma_k^2/(n-1) is the kk-th eigenvalue of the covariance matrix.

02

Why software uses the SVD

Read

You could form X⊤XX^\top X and take its eigenvectors. Libraries don't: forming X⊤XX^\top X squares the condition numberCondition numberLargest over smallest singular value. A large one means tiny input changes can swing the answer, and steps must be small., so tiny directions lose about twice as many digits to rounding.

Taking the SVD of XX directly keeps them. Both scikit-learn's PCA and R's prcomp work this way, and so does CodeSplash.

03

The best rank-k copy

Read

Keep only the kk largest singular values:

Xk=∑j=1kσj ujvj⊤.X_k = \sum_{j=1}^{k} \sigma_j\, u_j v_j^\top .

The Eckart–YoungLow-rank approximationKeep the k largest singular values and drop the rest: no other rank-k matrix is closer in squared error (Eckart–Young). result: no other rank-kk matrix is closer to XX in squared error. The error is exactly what you dropped,

∥X−Xk∥F2=∑j>kσj2.\lVert X - X_k \rVert_F^2 = \sum_{j>k} \sigma_j^2 .

So the scree plot reads two ways: variance kept by the first kk components, and reconstruction error left by the rest.

Python
import numpy as np

rng = np.random.default_rng(1)
X = rng.normal(size=(50, 4)) @ np.array([[1, .8, .6, 0], [0, .6, .8, 1], [0, 0, .1, 0], [0, 0, 0, .1]])
X = X - X.mean(0)
U, s, Vt = np.linalg.svd(X, full_matrices=False)
X2 = (U[:, :2] * s[:2]) @ Vt[:2]
print(np.sum((X - X2) ** 2), np.sum(s[2:] ** 2))   # equal
R
set.seed(1)
B <- rbind(c(1, .8, .6, 0), c(0, .6, .8, 1), c(0, 0, .1, 0), c(0, 0, 0, .1))
X <- scale(matrix(rnorm(200), 50) %*% B, scale = FALSE)
s <- svd(X)
X2 <- s$u[, 1:2] %*% diag(s$d[1:2]) %*% t(s$v[, 1:2])
c(sum((X - X2)^2), sum(s$d[-(1:2)]^2))             # equal
04

Rebuild a picture layer by layer

Explore

AExplorable · Low-rank pictures

How few rank-one layers does it take to rebuild a matrix?

How many rank-one layers will it take to keep 90% of this picture's squared size?

11
How sure?

Picture

2
0.10
OriginalRank 2What's left

Each singular value measures one rank-one layer. Keeping the largest k layers gives the best rank-k picture there is (Eckart–Young); the error is the size of the layers you drop.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Each layer is one singular value times an outer product of two singular vectors. Keep k layers and the error is the size of the layers you dropped, as Eckart–Young says. Compare the three rectangles, which are rank three, with static, which no small rank compresses.

05

PCA with a likelihood

Read

Plain PCA is geometry. Probabilistic PCAProbabilistic PCAPCA as a model: data = loadings × latent scores + equal-variance noise, so it has a likelihood and a BIC. turns it into a model:

x=Wz+μ+ε,z∼N(0,Iq),    ε∼N(0,σ2I).x = W z + \mu + \varepsilon, \qquad z \sim N(0, I_q),\;\; \varepsilon \sim N(0, \sigma^2 I).

Its maximum-likelihood WW spans the same top-qq directions as PCA. The noise variance σ2\sigma^2 is the average variance of the directions you dropped. Because it is a model, it has a log-likelihood, so you can compare ranks with BIC, fill missing cells by EM, and score how unusual a new row is.

06

PPCA chooses a rank

Read
Principal component analysisRecorded · Python and R agreeRecorded 2026-11-21 · 45 values compared
R

PCA of 4 variables: the first component explains 62.0% of the variance.

PC1 variance
62.0%
PC1 + PC2
86.8%

Plots

Scree plotHow many components carry most of the variance?
View data
ComponentCumulativeProportion of variance
10.62010.6201
20.86750.2474
30.95660.0891
410.0434
Biplot (PC1 × PC2)How do rows spread on the main components, and which variables drive each direction?

Loading arrows are rescaled to the score range.

View data
KindLabelPC1PC2
point0.9757−1.122
point1.931−1.062
point1.7450.7385
point−0.1400−1.109
point2.4991.527
point1.4990.9776
point−1.3451.078
point0.04720.3221
point2.983−0.0388
point1.623−1.266
point−0.90351.555
point−1.623−0.2089
point1.3650.6750
point−0.50040.1500
point−2.2310.1030
point−0.78890.2674
point−0.7433−0.9488
point1.549−0.8623
point−2.373−0.3726
point1.746−0.4234
point−0.48131.460
point2.0870.1538
point−1.6760.6259
point0.9865−2.370
point0.68980.2607
point−1.174−0.5315
point−1.2530.1920
point2.8460.7678
point−2.3600.0179
point0.17971.435
point1.960−0.1414
point1.6660.8149
point1.112−2.206
point−2.962−0.5931
point−0.22370.7348
point−0.30860.2850
point0.05850.5360
point−0.87950.5654
point−0.85511.477
point1.307−1.914
point−1.968−0.8151
point0.9897−0.8516
point1.3420.4083
point−0.54501.457
point−2.773−1.388
point−0.0954−0.1977
point−0.21470.9604
point−2.087−1.411
point−2.0590.6051
point−0.6231−0.3178
loadingMurder1.465−1.143
loadingAssault1.594−0.5139
loadingUrbanPop0.76062.386
loadingRape1.4860.4574

Explained variance

ComponentEigenvalueProportionCumulative
12.48062.0%62.0%
20.989824.7%86.8%
30.35668.9%95.7%
40.17344.3%100.0%

Loadings

VariablePC1PC2PC3PC4
Murder0.5359−0.4182−0.3412−0.6492
Assault0.5832−0.1880−0.26810.7434
UrbanPop0.27820.8728−0.3780−0.1339
Rape0.54340.16730.8178−0.0890

Probabilistic PCA by rank (σ² = noise variance; lowest BIC is the best rank)

Rankσ²Log-likelihoodParametersBIC
10.4965−253.479542.15
20.2597−237.8212522.58
30.1700−234.6414524.05
The exact R script · R R version 4.5.1 (2025-06-13)
# Principal component analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method discover.pca 1.2.0 · spec f98441aa79b6edf2
# Dataset: ml_usarrests (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

chart_rows <- function(n, cap = 2000) if (n <= cap) seq_len(n) else unique(round(seq(1, n, length.out = cap)))

# %% Data
FEATURES <- c("Murder", "Assault", "UrbanPop", "Rape")
LABEL <- NULL
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ml_usarrests.parquet", col_select = unique(c(FEATURES, LABEL))))
n_input <- nrow(df)
warnings <- list()
cs_check_finite_columns(df, FEATURES)
rows <- cs_ml_complete_rows(df, FEATURES)
if (length(rows) < n_input) {
  warnings <- c(warnings, sprintf("%d of %d rows were left out because a value was missing.", n_input - length(rows), n_input))
}
cs_check_rows(length(rows), 2, "Principal component analysis")
X <- cs_ml_numeric_matrix(df, FEATURES, rows)

# %% Principal components
SCALE <- TRUE
Z <- sweep(X, 2, colMeans(X))
if (SCALE) {
  s <- apply(X, 2, stats::sd)
  s[s == 0] <- 1
  Z <- sweep(Z, 2, s, "/")
}
k_max <- min(length(rows) - 1L, length(FEATURES))
p <- stats::prcomp(Z, center = FALSE, scale. = FALSE)
eig <- (p$sdev^2)[seq_len(k_max)]
prop <- eig / sum(eig)
cumulative <- cumsum(prop)
rot <- p$rotation[, seq_len(k_max), drop = FALSE]
signs <- cs_rep_canonical_signs(rot)  # largest |loading| positive (near-ties: the first)
loadings <- sweep(rot, 2, signs, "*")
scores <- sweep(p$x[, seq_len(k_max), drop = FALSE], 2, signs, "*")
k <- if (is.null(NULL)) k_max else min(as.integer(NULL), k_max)

# %% Artifacts
out <- cs_ml_out_dir("target/academy-parity/run-95359/discover.pca/usarrests_probabilistic/out-r")
emb <- data.frame(row = as.integer(rows))
for (j in seq_len(k)) emb[[paste0("dim_", j)]] <- scores[, j]
nanoparquet::write_parquet(emb, file.path(out, "embedding.parquet"))

# %% Result
values <- list(n = length(rows), n_variables = length(FEATURES), n_components = k,
               cum2 = if (k_max >= 2) cumulative[2] else NaN)
# Kaiser's "eigenvalue above 1" only means something on the correlation scale (scaled PCA).
if (SCALE) values$kaiser <- sum(eig > 1)
for (j in seq_len(k_max)) {
  values[[sprintf("eigen[%d]", j)]] <- eig[j]
  values[[sprintf("prop[%d]", j)]] <- prop[j]
  values[[sprintf("cumulative[%d]", j)]] <- cumulative[j]
}
for (j in seq_len(k)) {
  values[[sprintf("score_check[%d]", j)]] <- cs_ml_checksum(scores[, j], rows)
  for (i in seq_along(FEATURES)) values[[sprintf("loading[%d:%s]", j, FEATURES[i])]] <- unname(loadings[i, j])
}
ppca_table <- NULL
# Probabilistic PCA (Tipping & Bishop): closed-form ML noise variance, log-likelihood and BIC by rank
profile <- cs_rep_ppca_profile(eig, length(rows), length(FEATURES))
if (length(profile)) {
  want <- min(as.integer(2), length(FEATURES) - 1L)
  qs <- vapply(profile, function(d) d$q, numeric(1))
  bics <- vapply(profile, function(d) d$bic, numeric(1))
  chosen <- profile[[if (any(qs <= want)) max(which(qs <= want)) else 1L]]
  values$latent <- chosen$q
  values$sigma2 <- chosen$sigma2
  values$loglik <- chosen$loglik
  values$bic <- chosen$bic
  values$bic_rank <- qs[order(bics, qs)[1]]
  for (d in profile) values[[sprintf("bic[%d]", d$q)]] <- d$bic
  ppca_table <- list(key = "ppca", title = "Probabilistic PCA by rank (σ² = noise variance; lowest BIC is the best rank)",
                     columns = list(list(key = "q", label = "Rank", type = "integer"),
                                    list(key = "sigma2", label = "σ²", type = "number"),
                                    list(key = "loglik", label = "Log-likelihood", type = "number"),
                                    list(key = "df", label = "Parameters", type = "number"),
                                    list(key = "bic", label = "BIC", type = "number")),
                     rows = lapply(profile, function(d) list(q = d$q, sigma2 = d$sigma2, loglik = d$loglik, df = d$df, bic = d$bic)))
}
show <- min(k, 5L)
tables <- list(
  list(key = "variance", title = "Explained variance",
       columns = list(list(key = "component", label = "Component", type = "integer"),
                      list(key = "eigenvalue", label = "Eigenvalue", type = "number"),
                      list(key = "proportion", label = "Proportion", type = "percent"),
                      list(key = "cumulative", label = "Cumulative", type = "percent")),
       rows = lapply(seq_len(k_max), function(j) list(component = j, eigenvalue = eig[j], proportion = prop[j], cumulative = cumulative[j]))),
  list(key = "loadings", title = "Loadings",
       columns = c(list(list(key = "variable", label = "Variable")),
                   lapply(seq_len(show), function(j) list(key = paste0("pc", j), label = paste0("PC", j), type = "number"))),
       rows = lapply(seq_along(FEATURES), function(i) {
         r <- list(variable = FEATURES[i])
         for (j in seq_len(show)) r[[paste0("pc", j)]] <- unname(loadings[i, j])
         r
       }))
)
if (!is.null(ppca_table)) tables[[length(tables) + 1L]] <- ppca_table
charts <- list(cs_chart("scree", "scree-plot", "Scree plot", list(
  component = cs_col("Component", seq_len(k_max), "numeric"),
  variance = cs_col("Proportion of variance", prop, "numeric"),
  cumulative = cs_col("Cumulative", cumulative, "numeric")
)))
if (k_max >= 2) {
  pick <- chart_rows(length(rows))
  lab <- if (!is.null(LABEL)) as.character(df[[LABEL]][rows[pick] + 1L]) else rep("", length(pick))
  lab[is.na(lab)] <- ""
  reach <- max(abs(scores[pick, 1:2])) / max(max(abs(loadings[, 1:2])), 1e-12) * 0.8
  charts[[2]] <- cs_chart("biplot", "biplot", "Biplot (PC1 × PC2)", list(
    x = cs_col("PC1", c(scores[pick, 1], loadings[, 1] * reach), "numeric"),
    y = cs_col("PC2", c(scores[pick, 2], loadings[, 2] * reach), "numeric"),
    kind = cs_col("Kind", c(rep("point", length(pick)), rep("loading", length(FEATURES))), "categorical"),
    label = cs_col(if (is.null(LABEL)) "Label" else LABEL, c(lab, FEATURES), "categorical")
  ), note = "Loading arrows are rescaled to the score range.")
}
cs_publish(list(
  title = "Principal component analysis",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = length(rows),
  summary = sprintf("PCA of %d variables: the first component explains %.1f%% of the variance.", length(FEATURES), 100 * prop[1]),
  statistics = list(list(key = "prop1", label = "PC1 variance", value = prop[1], format = "percent"),
                    list(key = "cum2", label = "PC1 + PC2", value = values$cum2, format = "percent")),
  tables = tables,
  charts = charts,
  values = values,
  warnings = warnings,
  artifacts = list(list(key = "embedding", path = file.path(out, "embedding.parquet"), format = "parquet"))
))
Python

PCA of 4 variables: the first component explains 62.0% of the variance.

PC1 variance
62.0%
PC1 + PC2
86.8%

To keep this page light, the plots are shown once, under the R tab.

Explained variance

ComponentEigenvalueProportionCumulative
12.48062.0%62.0%
20.989824.7%86.8%
30.35668.9%95.7%
40.17344.3%100.0%

Loadings

VariablePC1PC2PC3PC4
Murder0.5359−0.4182−0.3412−0.6492
Assault0.5832−0.1880−0.26810.7434
UrbanPop0.27820.8728−0.3780−0.1339
Rape0.54340.16730.8178−0.0890

Probabilistic PCA by rank (σ² = noise variance; lowest BIC is the best rank)

Rankσ²Log-likelihoodParametersBIC
10.4965−253.479542.15
20.2597−237.8212522.58
30.1700−234.6414524.05
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Principal component analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method discover.pca 1.2.0 · spec f98441aa79b6edf2
# Dataset: ml_usarrests (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os

import numpy as np
import pandas as pd
from sklearn.decomposition import PCA

import codesplash as cs
from codesplash import ml as csml
from codesplash.ml import embed as csembed
from codesplash.ml import rep_linear as rl

def chart_rows(n, cap=2000):
    return np.arange(n) if n <= cap else np.unique(np.linspace(0, n - 1, cap).round().astype(int))

# %% Data
FEATURES = ["Murder", "Assault", "UrbanPop", "Rape"]
LABEL = None
df = pd.read_parquet("tests/parity/fixtures/ml_usarrests.parquet", columns=list(dict.fromkeys(FEATURES + ([LABEL] if LABEL else []))))
n_input = len(df)
warnings = []
cs.check_finite_columns(df, FEATURES)
rows = csembed.complete_rows(df, FEATURES)
if len(rows) < n_input:
    warnings.append(f"{n_input - len(rows)} of {n_input} rows were left out because a value was missing.")
cs.check_rows(len(rows), 2, "Principal component analysis")
X = csembed.numeric_matrix(df, FEATURES, rows)

# %% Principal components
SCALE = True
Z = csembed.standardize(X, ddof=1) if SCALE else X - X.mean(axis=0)  # SD with n − 1, like R's scale()
k_max = min(len(rows) - 1, len(FEATURES))
pca = PCA(n_components=k_max, svd_solver="full").fit(Z)
eig = pca.explained_variance_  # divisor n − 1 (= prcomp sdev²)
prop = eig / eig.sum()
cumulative = np.cumsum(prop)
signs = rl.canonical_signs(pca.components_.T)  # largest |loading| positive (near-ties: the first)
loadings = pca.components_.T * signs
scores = pca.transform(Z) * signs
k = k_max if None is None else min(int(None), k_max)

# %% Artifacts
out = csml.out_dir("target/academy-parity/run-95359/discover.pca/usarrests_probabilistic/out-python")
emb = pd.DataFrame({"row": rows.astype(np.int64)})
for j in range(k):
    emb[f"dim_{j + 1}"] = scores[:, j]
emb.to_parquet(os.path.join(out, "embedding.parquet"), index=False)

# %% Result
values = {
    "n": len(rows),
    "n_variables": len(FEATURES),
    "n_components": k,
    "cum2": float(cumulative[1]) if k_max >= 2 else float("nan"),
}
if SCALE:  # Kaiser's "eigenvalue above 1" only means something on the correlation scale
    values["kaiser"] = int(np.sum(eig > 1))
for j in range(k_max):
    values[f"eigen[{j + 1}]"] = float(eig[j])
    values[f"prop[{j + 1}]"] = float(prop[j])
    values[f"cumulative[{j + 1}]"] = float(cumulative[j])
for j in range(k):
    values[f"score_check[{j + 1}]"] = csembed.checksum(scores[:, j], rows)
    for i, f in enumerate(FEATURES):
        values[f"loading[{j + 1}:{f}]"] = float(loadings[i, j])
ppca_table = None
# Probabilistic PCA (Tipping & Bishop): closed-form ML noise variance, log-likelihood and BIC by rank
profile = rl.ppca_profile(eig, len(rows), len(FEATURES))
if profile:
    want = min(int(2), len(FEATURES) - 1)
    pick_q = [d for d in profile if d["q"] <= want] or profile[:1]
    chosen = pick_q[-1]
    values["latent"] = chosen["q"]
    values["sigma2"] = chosen["sigma2"]
    values["loglik"] = chosen["loglik"]
    values["bic"] = chosen["bic"]
    values["bic_rank"] = min(profile, key=lambda d: (d["bic"], d["q"]))["q"]
    for d in profile:
        values[f"bic[{d['q']}]"] = d["bic"]
    ppca_table = {
        "key": "ppca",
        "title": "Probabilistic PCA by rank (σ² = noise variance; lowest BIC is the best rank)",
        "columns": [
            {"key": "q", "label": "Rank", "type": "integer"},
            {"key": "sigma2", "label": "σ²", "type": "number"},
            {"key": "loglik", "label": "Log-likelihood", "type": "number"},
            {"key": "df", "label": "Parameters", "type": "number"},
            {"key": "bic", "label": "BIC", "type": "number"},
        ],
        "rows": [{"q": d["q"], "sigma2": d["sigma2"], "loglik": d["loglik"], "df": d["df"], "bic": d["bic"]} for d in profile],
    }
show = min(k, 5)
tables = [
    {
        "key": "variance",
        "title": "Explained variance",
        "columns": [
            {"key": "component", "label": "Component", "type": "integer"},
            {"key": "eigenvalue", "label": "Eigenvalue", "type": "number"},
            {"key": "proportion", "label": "Proportion", "type": "percent"},
            {"key": "cumulative", "label": "Cumulative", "type": "percent"},
        ],
        "rows": [{"component": j + 1, "eigenvalue": eig[j], "proportion": prop[j], "cumulative": cumulative[j]} for j in range(k_max)],
    },
    {
        "key": "loadings",
        "title": "Loadings",
        "columns": [{"key": "variable", "label": "Variable"}] + [{"key": f"pc{j + 1}", "label": f"PC{j + 1}", "type": "number"} for j in range(show)],
        "rows": [dict({"variable": f}, **{f"pc{j + 1}": loadings[i, j] for j in range(show)}) for i, f in enumerate(FEATURES)],
    },
]
if ppca_table is not None:
    tables.append(ppca_table)
charts = [
    cs.chart(
        "scree",
        "scree-plot",
        "Scree plot",
        {
            "component": cs.col("Component", list(range(1, k_max + 1)), "numeric"),
            "variance": cs.col("Proportion of variance", prop, "numeric"),
            "cumulative": cs.col("Cumulative", cumulative, "numeric"),
        },
    )
]
if k_max >= 2:
    pick = chart_rows(len(rows))
    lab = ["" if LABEL is None else str(v) for v in df.iloc[rows[pick]][LABEL]] if LABEL else [""] * len(pick)
    reach = np.max(np.abs(scores[pick, :2])) / max(np.max(np.abs(loadings[:, :2])), 1e-12) * 0.8
    charts.append(
        cs.chart(
            "biplot",
            "biplot",
            "Biplot (PC1 × PC2)",
            {
                "x": cs.col("PC1", np.concatenate([scores[pick, 0], loadings[:, 0] * reach]), "numeric"),
                "y": cs.col("PC2", np.concatenate([scores[pick, 1], loadings[:, 1] * reach]), "numeric"),
                "kind": cs.col("Kind", ["point"] * len(pick) + ["loading"] * len(FEATURES), "categorical"),
                "label": cs.col(LABEL or "Label", lab + FEATURES, "categorical"),
            },
            note="Loading arrows are rescaled to the score range.",
        )
    )
cs.publish(
    {
        "title": "Principal component analysis",
        "engine": cs.engine_info("scikit-learn", "numpy", "pandas"),
        "n": len(rows),
        "summary": f"PCA of {len(FEATURES)} variables: the first component explains {prop[0]:.1%} of the variance.",
        "statistics": [
            {"key": "prop1", "label": "PC1 variance", "value": float(prop[0]), "format": "percent"},
            {"key": "cum2", "label": "PC1 + PC2", "value": values["cum2"], "format": "percent"},
        ],
        "tables": tables,
        "charts": charts,
        "values": values,
        "warnings": warnings,
        "artifacts": [{"key": "embedding", "path": os.path.join(out, "embedding.parquet"), "format": "parquet"}],
    }
)

On standardized US arrests, BIC is 542.2 for one component, 522.6 for two and 524.0 for three, so it keeps 2. The noise variance is 0.260: the average of the two dropped eigenvalues, with nn rather than n−1n-1 in the divisor.

On iris without scaling, BIC prefers 3 components, even though the first holds most of the variance. BIC weighs fit against parameters; "most of the variance" is a different question.

07

Readiness

Read
  • PCA (REP001) runs in CodeSplash: Discover → Principal component analysis, in Python and R with matching results.
  • Probabilistic PCA (REP002) partly runs: set Model to Probabilistic PCA for σ2\sigma^2, the log-likelihood and BIC for every rank, or set Missing values to Fill from probabilistic PCA (PPCA-EM). The readiness badge above shows the current label.
08

Check: SVD and PPCA

Checkpoint

Check yourself

A centered matrix has singular values 6, 3, 2 and 1. What is the squared Frobenius error of its best rank-2 approximation?

Show the answer

Answer: 5

Eckart–Young: the dropped singular values squared, 22+12=52^2 + 1^2 = 5.

Check yourself

Why do PCA implementations take the SVD of XX rather than the eigenvectors of X⊤XX^\top X?

Show the answer

Answer: b

Both routes give the same components in exact arithmetic. In floating point, the SVD of XX keeps about twice as many correct digits in the small directions.

Check yourself

In probabilistic PCA with qq components, what is the maximum-likelihood noise variance σ2\sigma^2?

Show the answer

Answer: c

Whatever the kept directions don't explain is treated as isotropic noise, so σ2\sigma^2 averages the discarded eigenvalues.

Check yourself · choose all that apply

What does probabilistic PCA give you that plain PCA doesn't? Pick all that apply.

Show the answer

Answer: a, b, d

The directions are the same; the noise model is what adds a likelihood, EM for gaps and a density for new rows.

Check yourself

The first component holds 92% of the variance, yet PPCA's BIC picks three components. Is that a contradiction?

Show the answer

Answer: b

The leftover variance may still have structure the noise model can't absorb cheaply. Variance share and BIC answer different questions.

09

Recap

Recap
  • X=UΣV⊤X = U\Sigma V^\top: VV gives PCA directions, UΣU\Sigma the scores, σk2/(n−1)\sigma_k^2/(n-1) the eigenvalues.
  • Keeping the top kk singular values gives the best rank-kk copy; the error is the sum of dropped σj2\sigma_j^2.
  • Probabilistic PCA adds a noise variance and a likelihood, so ranks can be compared and gaps filled.

Concepts in this lesson