This project demonstrates Principal Component Analysis (PCA) using Eigen Decomposition in C++.
It reduces a 2D dataset to 1D and visualizes the result using matplotlib-cpp.
dataset.hpp
→ Generate 2D datasetcenter.hpp
→ Center datacovariance.hpp
→ Compute covariance matrixeigen.hpp
→ Eigen decompositionpca_projection.hpp
→ Project data & variance explainedplot.hpp
→ Reconstruct & plot datamain.cpp
→ Integrates all partsCMakeLists.txt
→ Build configuration
- Clone repository and include
matplotlib-cpp
folder. Usegit clone https://github.com/lava/matplotlib-cpp
command. - C++ Compiler (g++ recommended, C++17 support)
- Python 3.13 (or compatible version)
- Python packages:
numpy
andmatplotlib
Install Python packages:
python -m pip install numpy matplotlib
```bash
mkdir build && cd build
cmake ..
make
## Run
./PCA_Assignment