Estimate the optimal number of components in PCA-based dimension reduction.
Project description
Estimate the optimal number of components in a PCA, using the SHEM procedure: Split-Half Eigenvector Matching.
The get_n_components function estimates the true (or "generating") number of principal components. While scree/elbow/knee criteria for the eigenvalues curve is common, this is known to be a very fallible heuristic. The rationale of this alternative procedure is that true principal components should be found in random split halves of the data. The estimate is therefore based on measuring the similarity of eigenvectors between a set of split-halves; i.e., the procedure doesn't use the shape of the eigenvalue curve. Instead, a separation is made between components with high versus low split-half similarity.
Detail: For an nd-array X, with shape == (nObservations, nVariables), a number of random splits are performed. For each split separately, a PCA is performed, via eigendecomposition of the covariance matrix of X. Each of the first split's eigenvectors is matched to the most-similar of the second split's eigenvectors. Similarity is measured via the dot product. The vector of similarities is sorted from high to low, and the vectors are averaged over all random splits. Finally, the optimal seperation between the high versus low similarities is determined by a basic between-within variance criterion. An estimated zero components is possible.
Usage:
O = teg_get_best_n.get_n_components(X)
This returns a dictionary with the estimated number of components in O['nComponents'], as well as the eigenvalues (O['eigenvalues']) and eigenvectors (O['eigenvectors']).
Example.py contains tests with simulated data to check how well the true number of latent variables, used to generate simulated data, is recovered.
Project details
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
File details
Details for the file teg_get_best_n-0.0.6.tar.gz
.
File metadata
- Download URL: teg_get_best_n-0.0.6.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 610208dccd73cc027e575f7a0b78b0357b9dc0cbbd008f91d25606250d134f7c |
|
MD5 | efde821870427a8106369cf913b32bb1 |
|
BLAKE2b-256 | ca86887281f2db256d8fa9eb4552176fc7b45ddf12d2755071891d3323824daa |
File details
Details for the file teg_get_best_n-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: teg_get_best_n-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0158c0ee30f22472bc14b169d5628401a8b8ae5e9f0ba66ad7c75b935e60bd |
|
MD5 | 5d7f78a49c2ff4d2f2e1db77a5aeaea7 |
|
BLAKE2b-256 | 417b634f2686d32ad80c0f999533924bf4dd699b00c8f3ff5317b80398c5429c |