Skip to content

Conversation

@Siddhram
Copy link
Contributor

This PR introduces a fully documented implementation of Principal Component Analysis (PCA) in R, designed for dimensionality reduction and feature extraction from high-dimensional datasets.

Overview

The pca_algorithm function reduces high-dimensional data into a smaller set of uncorrelated principal components while preserving as much variance as possible. It standardizes the dataset, computes the covariance matrix, performs eigen decomposition, and projects the data onto the top k principal components.

Features

  • Reduces dimensionality of numeric datasets
  • Standardizes input data to zero mean and unit variance
  • Computes covariance matrix and performs eigen decomposition
  • Selects top k principal components for projection
  • Returns reduced data, eigenvectors (components), and eigenvalues
  • Suitable for preprocessing in machine learning, visualization, and noise reduction

Complexity

  • Time Complexity: O(n * d² + d³) where n = samples, d = features
  • Space Complexity: O(d² + n * d)

Demonstration

Run the included example to reduce a dataset to k principal components. The algorithm outputs the projected reduced data, top components, and eigenvalues for analysis.

@Siddhram Siddhram changed the title Add Principal Component Analysis in R Add Principal Component Analysis Algorithm in R Oct 18, 2025
@siriak siriak enabled auto-merge (squash) October 23, 2025 15:12
@siriak siriak merged commit 1f47a7b into TheAlgorithms:master Oct 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants