Module 13
Fundamentals of Dimensionality Reduction
Conceptual Overview: * In machine learning, data is typically represented as a matrix with dimensions , where is the number of data points and is the number of attributes or features. * Dimensionality reduction involves transforming the original data into a new set of data with dimensions , such that k < D. * The primary goal is to perform data compression while preserving the essential parts of the original information.
Objectives and Benefits: * Data Smoothing: Reducing dimensions helps extract the "essence" of the data while discarding noise. * Improved Generalization: By eliminating noise and redundant features, the transformed data can lead to better performance in classification and regression models. * Overfitting Mitigation: Reducing the parameter space is a practical way to deal with overfitting. * Computational Efficiency: Smaller datasets require smaller models, leading to faster training times, more frequent experimentation, and more efficient hyperparameter searches. * Deployment: Models trained on reduced dimensions are easier to deploy and faster to execute in real-world predictive applications.
Mathematical Background: Covariance and Correlation
Covariance Definition: * Given two vectors and , each of length , the average (expectation) is defined as and . * The covariance between and is calculated as: * This represents the dot product of the mean-centered vectors divided by the number of observations.
Intuition of Covariance: * Covariance measures the correlation between two attributes. * A high covariance indicates a high correlation. For example, if is temperature in Celsius and is temperature in Fahrenheit, the covariance will be a high number due to their linear relationship. * If attributes are highly correlated, it suggests that some attributes can be dropped without losing significant information, which motivates dimensionality reduction.
Standardization: * Before calculating the covariance matrix, data should be standardized. * For every column (attribute) in matrix , the average value of that column is subtracted from every entry in that column, resulting in a mean of zero for all attributes.
The Covariance Matrix: * Assuming is an standardized matrix, the covariance matrix is defined as: * The resulting matrix has dimensions . * The entry represents the covariance between attribute and attribute . This matrix captures all pairwise correlations across the entire dataset.
Linear Algebra: Eigenvectors and Eigenvalues
Matrix Action on Vectors: * Applying a matrix to a vector (multiplication) generally rotates the vector and changes its length. * For a symmetric matrix , there exist special vectors called eigenvectors that do not change direction when the matrix is applied.
Eigenvector/Eigenvalue Equation: * A vector is an eigenvector of matrix if: * Here, (lambda) is the eigenvalue, which represents the factor by which the eigenvector is stretched or shrunk.
Example Calculation: * Consider the matrix . * For vector : Thus, is an eigenvector with eigenvalue . * For vector : Thus, is an eigenvector with eigenvalue .
Properties of Eigenvectors for Symmetric Matrices: * Orthogonality: Any two eigenvectors corresponding to different eigenvalues are orthogonal (their dot product is zero). In the example above: . * Frobenius Norm Connection: For a symmetric matrix, the sum of all squared entries is equal to the sum of the squared eigenvalues: * The term on the left is known as the Frobenius norm of the matrix.
Principal Component Analysis (PCA)
Intuition of Principal Components: * In a multi-dimensional space, there is a single direction along which the data exhibits the highest variance. This is the First Principal Component (). * The Second Principal Component () is the direction that maximizes variance among all directions orthogonal to . * This continues until components are identified for a -dimensional space.
Variance Maximization: * PCA seeks to find a direction vector that maximizes the variance of the projected data points. * Projecting points onto a line creates a new set of values along that line. The variance along that direction is: * The first principal component is the direction that maximizes this scalar value.
Algorithmic Steps for PCA: 1. Standardize the dataset so that each attribute has a mean of zero. 2. Compute the covariance matrix . 3. Solve the eigenvalue problem: . 4. Sort the eigenvalues in descending order: \lambda_1 > \lambda_2 > \dots > \lambda_D. 5. Select the top eigenvectors corresponding to the largest eigenvalues. These eigenvectors are the principal components. 6. Construct the transformation matrix (of size ) using these eigenvectors as columns. 7. Transform the data: .
Selecting the Number of Components (k): * The eigenvalues represent the amount of variance explained by each corresponding principal component. * Total variance can be measured by the sum of squared eigenvalues. * A common practice is to choose such that the cumulative explained variance meets a threshold, such as
Kernel Principal Component Analysis (Kernel PCA)
The Dual Problem: * The standard PCA equation is . * Multiplying by on the left gives: . * Letting , we get: . * This is an eigenvalue problem for the matrix , which has dimensions .
Similarity and the Kernel Trick: * The entry in the matrix represents the inner product (similarity) between data point and data point . * Standard PCA uses a linear similarity (the dot product). * Kernel PCA replaces this dot product with a kernel function , which represents similarity in a higher-dimensional engineered space without explicitly computing that space. * Common kernels include the RBF (Radial Basis Function) or Gaussian kernel:
Nonlinear Separation: * Linear PCA may fail to separate data that is not linearly separable (e.g., concentric circles or interleaved half-moons). * Kernel PCA can transform these datasets into a new space where they become linearly separable.
Implementation Considerations for Kernel PCA: * Computational Efficiency: Because Kernel PCA involves an matrix, it can be computationally intensive or infeasible for very large datasets. * Re-centering: The kernel matrix must be re-centered so that every row and column has an average of zero, ensuring the data is standardized in the high-dimensional space. * Test Set Transformation: When applying the transformation to a test set, the statistics (mean-centering parameters) from the training set must be used to ensure consistency.
Experimental Results and Observations
Wine Dataset Experiment: * Initial dimension: 13 attributes. * Top two eigenvalues explained approximately and of the variance respectively, totaling * After projecting from 13D to 2D, a logistic regression classifier achieved high accuracy with clear linear separation between classes.
Nonlinear Datasets: * Two Moons: Standard PCA only rotates the data, maintaining the lack of linear separability. Kernel PCA (RBF kernel with ) transforms the mooons into a configuration that is linearly separable. * Concentric Circles: Standard PCA results in significant overlap when reduced to 1D. Kernel PCA yields a transformation where the circles are clearly separated, potentially even along a single principal component axis.