Skip to content

    PCA (Dimensionality Reduction)

    Machine Learning · Advanced

    Definition

    PCA projects data onto new axes (principal components) that capture the most variance.

    Reduces features, speeds models and helps visualization.

    Diagram

    x1, x2→ PC1 (most varianc…→ PC2

    Flowchart

    Standardize dataCompute covariance matrixFind eigenvectorsKeep top-k componentsProject data

    Example: Variance explained

    eig = [4.0, 1.0]
    print(eig[0] / sum(eig))

    Output: 0.8

    Complexity

    O(n·d² + d³)

    Key points

    • Components are orthogonal
    • Always scale features first

    Interview questions

    How many components to keep?

    Enough to explain ~90–95% of the variance.

    More Machine Learning topics