PyTorch implementation of PCA (similar to sklearn PCA).
Project description
Pytorch Principal Component Analysis (PCA)
Principal Component Anlaysis (PCA) in PyTorch. The intention is to provide a
simple and easy to use implementation of PCA in PyTorch, the most similar to
the sklearn
's PCA as possible (in terms of API and, of course, output).
Links
Github repository: https://github.com/valentingol/torch_pca
Pypi project: https://pypi.org/project/torch_pca/
Documentation: https://torch-pca.readthedocs.io/en/latest/
Installation
Simply install it with pip:
pip install torch-pca
How to use
Exactly like sklearn.decomposition.PCA
but it uses PyTorch tensors as input and output!
from torch_cpa import PCA
# Create like sklearn.decomposition.PCA, e.g.:
pca_model = PCA(n_components=None, svd_solver='full')
# Use like sklearn.decomposition.PCA, e.g.:
>>> new_train_data = pca_model.fit_transform(train_data)
>>> new_test_data = pca_model.transform(test_data)
>>> print(pca.explained_variance_ratio_)
[0.756, 0.142, 0.062, ...]
More details and features in the API documentation.
Implemented features
-
fit
,transform
,fit_transform
methods. - All attributes from sklean's PCA are available:
explained_variance_(ratio_)
,singular_values_
,components_
,mean_
,noise_variance_
, ... - Full SVD solver
- SVD by covariance matrix solver
- (absent from sklearn) Decide how to center the input data in
transform
method (default is like sklearn's PCA) - Find number of components with explained variance proportion
- Automatically find number of components with MLE
-
inverse_transform
method
To be implemented
- Whitening option
- Randomized SVD solver
- ARPACK solver
-
get_covariance
method -
get_precision
method andscore
method - Support sparse matrices
Contributing
Feel free to contribute to this project! Just fork it and make an issue or a pull request.
See the CONTRIBUTING.md file for more information.
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
Hashes for torch_pca-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9be4723e4bcbfaac5436480b79a69084b8e739907dc338a8d95a2f98fcb5d1b8 |
|
MD5 | 7b39446553ddaa7196510b35644b6aa4 |
|
BLAKE2b-256 | d7bf522b22c71452bab98cf94a18c509c1e7aad737e89fe89d2876bed9d1a5ea |