Cosine similarity and PCA (cov + SVD) from scratch in NumPy with tests
Project description
Run in Google Colab
Notebooks
Interactive demos are in the notebooks/ folder.
- Cosine_PCA_FromScratch.ipynb
Demonstrates cosine similarity, PCA (covariance + SVD), explained variance plots, and reconstruction.
Run in Binder
Cosine_PCA
linalg_fromscratch (NumPy) — Cosine + PCA with Tests
A tiny, dependency-light set of linear algebra utilities implemented from scratch in NumPy, with a pytest suite you can drop into any repo.
Structure
linalg_fromscratch/
├── src/
│ └── linalg_fromscratch/
│ ├── __init__.py
│ ├── cosine.py
│ └── pca.py
├── tests/
│ ├── test_cosine.py
│ └── test_pca.py
├── pytest.ini
├── requirements.txt
└── README.md
Run tests
pip install -r requirements.txt
pytest
Notes
- Cosine similarity guards against zero vectors.
PCA_FromScratch: covariance eigendecomposition.PCA_SVD: SVD-based PCA. Tests confirm equivalence up to sign flips.- Tests include:
- Cosine edge cases
- Orthonormality of components
- Variance-along-PCs equals eigenvalues
- Reconstruction error decreases with more components
- Covariance-PCA vs SVD-PCA numerical equivalence
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file linalg_fromscratch-0.1.1.tar.gz.
File metadata
- Download URL: linalg_fromscratch-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4aff1a20205cd35c0c87b0834c98363500ce7dd9c5b7965d5cf6ca7cc2049ce
|
|
| MD5 |
6f198213dea3b400616d237a05980d7e
|
|
| BLAKE2b-256 |
69819d69b21b98fc300c54854003c8a547da0aeacd2c50c64aa77d6939db894d
|
File details
Details for the file linalg_fromscratch-0.1.1-py3-none-any.whl.
File metadata
- Download URL: linalg_fromscratch-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef4bb982fda73c94a6a14d530e6f67b0467d8da4991dfe6466a778721abd0854
|
|
| MD5 |
98a086359f4fddc83fb2196a24022255
|
|
| BLAKE2b-256 |
29b85247943e4e628743990d06931b2c590bde68179b2df6aaf86b10a3ea1bcb
|