Lecture 7

📚 Lecture 7.pdf

Brief overview

This document introduces Principal Component Analysis (PCA), a technique for reducing data dimensionality by transforming variables into new uncorrelated components. Understanding PCA is crucial for simplifying complex datasets while retaining essential information for analysis.

Key points

  • Overview of Principal Component Analysis (PCA) and its purpose in data dimension reduction.
  • How to compute and interpret the first and second principal components.
  • The impact of variable scaling and the uniqueness of principal components.
  • Methods for selecting the appropriate number of principal components to retain.
  • The mathematical foundation of PCA through eigenvalues and eigenvectors.

1. Introduction to principal component analysis

1.1 What is principal component analysis?

PCA is a method for reducing data dimensions. It involves computing principal components.

These components are then used to understand the data. PCA is an unsupervised approach.

This means it does not require a target variable.

PCA can be used for several purposes:

  • Deriving new variables for supervised learning methods.
  • Visualizing data, which can include variables or observations.

1.2 Computing the first principal component

The first principal component (PC1) is the direction that captures the most variance in the data. It is found by identifying the eigenvector associated with the largest eigenvalue of the covariance matrix.

This eigenvector represents the direction of maximum variability.

Consider a dataset with two variables, X1X_1 and X2X_2. The first principal component is a linear combination of these variables: z1=ϕ11X1+ϕ12X2z_1 = \phi_{11}X_1 + \phi_{12}X_2 Here, ϕ11\phi_{11} and ϕ12\phi_{12} are the components of the first loading vector.

The loading vector indicates how the original variables contribute to the principal component.

📝 Example: If a dataset includes "crime rate" and "urbanization level," PC1 might represent the general "level of criminal activity."

1.3 Interpreting the first principal component

Interpretation of the first principal component depends on the meaning of the original variables. The loading vector's values, ϕ1j\phi_{1j}, show the weight of each original variable XjX_j in the component.

Larger absolute values indicate a stronger influence.

  • Positive loading: If a variable has a positive loading, increases in that variable contribute to an increase in the principal component's value.
  • Negative loading: If a variable has a negative loading, increases in that variable contribute to a decrease in the principal component's value.

📝 Example: In a dataset of US states, with variables like "Assault," "Murder," "Rape," and "UrbanPop," PC1 might have roughly equal positive loadings for "Assault," "Murder," and "Rape." A low loading for "UrbanPop" suggests it influences PC1 less. This component would then represent overall rates of serious crimes.

1.4 Computing the second principal component

The second principal component (PC2) captures the second largest amount of variance in the data. It is orthogonal (uncorrelated) to the first principal component.

PC2 corresponds to the eigenvector associated with the second largest eigenvalue.

The second principal component is also a linear combination of the original variables: z2=ϕ21X1+ϕ22X2z_2 = \phi_{21}X_1 + \phi_{22}X_2 The loadings ϕ21\phi_{21} and ϕ22\phi_{22} are the components of the second loading vector. This vector is orthogonal to the first loading vector.

1.5 Interpreting the second principal component

The interpretation of PC2 also relies on the original variables and their loadings. PC2 explains the remaining variance not accounted for by PC1.

It represents a different pattern or dimension within the data.

📝 Example: Continuing with the US states data, PC2 might have a large positive loading primarily for "UrbanPop." This would suggest that PC2 represents the level of urbanization of a state. States with high urbanization would score high on PC2.

1.6 Principal component decomposition and plotting

PCA decomposes the original data into principal components. These components can be plotted to visualize the data in a lower-dimensional space.

Plotting the first two principal components is common for exploratory data analysis.

  • Plotting observations: Each data point is represented by its scores on PC1 and PC2.
  • Plotting variables: The loading vectors can be visualized on the same plot. This shows how original variables relate to the principal components.

🔑 Important: PCA helps understand the main patterns of variation in data by transforming variables into a new set of uncorrelated components.

2. Scaling and uniqueness of principal components

2.1 Scaling variables

  • Scaling is crucial for PCA results.
  • Unscaled variables with different units heavily influence PCA.
  • Variables with higher variance dominate the first principal component.
  • Consider scaling if variables are measured in different units.

2.2 Uniqueness of principal components

  • The document mentions the uniqueness of principal components but does not elaborate on this aspect on the provided pages.

2.3 How many principal components to use

  • Supervised analysis offers an objective method.

    • Treat the number of principal component scores as a tuning parameter.
    • Select this parameter using cross-validation or similar techniques.
  • Scree plots help decide the number of components.

    • Examine scree plots to identify an "elbow."
    • The elbow is where the variance explained by subsequent components drops significantly.
    • This suggests retaining components before the elbow.
  • Objective methods for selecting components are not well-established.

2.3.1 Interpreting scree plots

  • Scree plots visualize the proportion of variance explained by each principal component.
  • Look for a point where the explained variance sharply decreases.
  • This point, the "elbow," indicates where fewer components are needed.
  • For example, an elbow after the second component suggests using the first two.

🔑 Important: While scree plots and cross-validation offer guidance, there is no universally agreed-upon objective method to determine the ideal number of principal components.

📝 Example: Applying PCA to the USArrests data might involve producing a scree plot. If the plot shows a steep drop after the first two components, you might decide to retain those two.

🔑 Important: The number of principal components to use is a decision that balances explaining variation with simplifying the model.

3. Eigenvalues and eigenvectors in PCA

3.1 Understanding eigenvalues and eigenvectors

Eigenvalues and eigenvectors are fundamental to Principal Component Analysis (PCA). They help us understand the variance within a dataset and identify the most important directions of that variance.

In PCA, we are looking for specific vectors (directions) in our data that capture the most spread or variance.

🔑 Important: Eigenvectors represent directions of maximum variance in data, and eigenvalues quantify the amount of variance along those directions.

When a linear transformation (like PCA) is applied to a vector, and the output vector is simply a scaled version of the original, the original vector is called an eigenvector. The scaling factor is the eigenvalue.

Av=λvA\mathbf{v} = \lambda\mathbf{v}

In this equation:

  • AA is the transformation matrix (e.g., the covariance matrix of the data).
  • v\mathbf{v} is the eigenvector, a non-zero vector.
  • λ\lambda (lambda) is the eigenvalue, a scalar representing the scaling factor.

📝 Example: Imagine stretching a rubber sheet. If you mark a line on the sheet and, after stretching, that line is still a straight line passing through the same point but just longer or shorter, that line represents an eigenvector, and the amount of stretch is its eigenvalue.

3.2 Calculating eigenvalues and eigenvectors

To find the eigenvalues and eigenvectors of a matrix AA, we rearrange the eigenvalue equation Av=λvA\mathbf{v} = \lambda\mathbf{v}. This becomes (A−λI)v=0(A - \lambda I)\mathbf{v} = \mathbf{0}, where II is the identity matrix.

For a non-trivial solution (i.e., v≠0\mathbf{v} \neq \mathbf{0}), the matrix (A−λI)(A - \lambda I) must be singular. This means its determinant must be zero.

det⁡(A−λI)=0\det(A - \lambda I) = 0

This equation is called the characteristic equation. Solving it for λ\lambda gives the eigenvalues.

🔑 Important: The characteristic equation is key to finding eigenvalues; setting the determinant of (A−λI)(A - \lambda I) to zero provides the polynomial whose roots are the eigenvalues.

Once the eigenvalues (λ\lambda) are found, we substitute each one back into the equation (A−λI)v=0(A - \lambda I)\mathbf{v} = \mathbf{0} to solve for the corresponding eigenvector(s) v\mathbf{v}. This involves solving a system of linear equations.

🔑 Important: For each eigenvalue, you solve a system of linear equations to find its associated eigenvector.

3.2.1 Finding eigenvalues

The process of finding eigenvalues involves solving the characteristic equation. This equation is a polynomial in λ\lambda.

The degree of the polynomial is equal to the dimension of the matrix AA.

Consider a 2x2 matrix AA: A=(abcd)A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} The characteristic equation is: det⁡(a−λbcd−λ)=0\det \begin{pmatrix} a-\lambda & b \\ c & d-\lambda \end{pmatrix} = 0 This expands to: (a−λ)(d−λ)−bc=0(a-\lambda)(d-\lambda) - bc = 0 λ2−(a+d)λ+(ad−bc)=0\lambda^2 - (a+d)\lambda + (ad-bc) = 0 The terms (a+d)(a+d) and (ad−bc)(ad-bc) are the trace and determinant of matrix AA, respectively.

3.2.2 Finding eigenvectors

After finding an eigenvalue λ\lambda, we plug it back into (A−λI)v=0(A - \lambda I)\mathbf{v} = \mathbf{0}.

For a 2x2 matrix, if λ1\lambda_1 is an eigenvalue, we solve: (a−λ1bcd−λ1)(v1v2)=(00)\begin{pmatrix} a-\lambda_1 & b \\ c & d-\lambda_1 \end{pmatrix} \begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix} This yields two equations: (a−λ1)v1+bv2=0(a-\lambda_1)v_1 + bv_2 = 0 cv1+(d−λ1)v2=0cv_1 + (d-\lambda_1)v_2 = 0 These two equations are linearly dependent (one is a multiple of the other). We use one to find the relationship between v1v_1 and v2v_2, determining the direction of the eigenvector.

Any non-zero scalar multiple of a solution is also a valid eigenvector.

📝 Example: If solving for an eigenvector gives v1=2v2v_1 = 2v_2, we can choose v2=1v_2=1, then v1=2v_1=2. The eigenvector would be (21)\begin{pmatrix} 2 \\ 1 \end{pmatrix}. Another valid eigenvector is (42)\begin{pmatrix} 4 \\ 2 \end{pmatrix}.

3.3 Eigenvalues and eigenvectors in PCA

In PCA, the covariance matrix (or correlation matrix) of the data is used as the transformation matrix AA.

  • Eigenvectors of the covariance matrix: These represent the directions of maximum variance in the data. These directions are orthogonal to each other. They are called the principal components.
  • Eigenvalues of the covariance matrix: These indicate the magnitude of the variance along the corresponding eigenvector (principal component). A larger eigenvalue means more variance is captured by that principal component.

🔑 Important: Eigenvectors of the covariance matrix are the principal components; their corresponding eigenvalues represent the variance along these components.

PCA works by sorting the eigenvalues in descending order. The eigenvector associated with the largest eigenvalue represents the first principal component, capturing the most variance.

The eigenvector with the second largest eigenvalue represents the second principal component, capturing the next most variance, and so on.

🔑 Important: Order of principal components is determined by the magnitude of their corresponding eigenvalues (largest to smallest).

This allows us to reduce the dimensionality of the data. We can often retain most of the important information by keeping only the first few principal components, those with the largest eigenvalues.

📝 Example: If the first eigenvalue is 50 and the second is 10, the first principal component explains much more of the data's spread than the second. We might choose to keep only the first component if acceptable variance is maintained.

Matrix ComponentPCA MeaningSignificance
EigenvectorDirection of a principal componentRepresents a linear combination of original features
EigenvalueVariance explained by the principal componentMagnitude of variance along the eigenvector

> Cheat Table: Eigenvalues/Eigenvectors in PCA

ConceptRole in PCA
EigenvectorsDefine the directions of principal components
EigenvaluesQuantify the variance captured by each component

This topic is crucial for understanding how PCA identifies the most important underlying patterns in data. The eigenvectors provide the new axes (principal components), and the eigenvalues tell us how much information (variance) each new axis holds.

> Important: Eigenvalues and eigenvectors reveal the intrinsic dimensionality and structure of data by identifying directions of maximal variance.

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also