Skip to main content

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.

Metadata

Release files for teg-get-best-n 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for teg-get-best-n 0.0.7
File Size Uploaded
teg_get_best_n-0.0.7.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for teg-get-best-n 0.0.7
File Interpreter ABI Platform
teg_get_best_n-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / teg_get_best_n-0.0.7.tar.gz

Download URL teg_get_best_n-0.0.7.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
18db35d9adcf6212211b60fdd05f6843dff9921ba04afa9af2df2d3cfcfecfa5
BLAKE2b-256 checksum
How to use checksums
b969590bc381dfcfebd10fcf85a3a444636213ce388862de54d4ec69476aebc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.5

Release files / teg_get_best_n-0.0.7-py3-none-any.whl

Download URL teg_get_best_n-0.0.7-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3168b50610c7bbb98627c1ed478f071bdfd4920d20466a3c5ccbbe5d5536ce41
BLAKE2b-256 checksum
How to use checksums
ec26a9b2f44a5326da7a9cf23b18de02eb870cfd66e27150ef35383f12877983
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page