Skip to main content

PyTorch implementation of PCA (similar to sklearn PCA).

Project description

Pytorch 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).

PythonVersion PytorchVersion

GitHub User followers GitHub User's User stars

Ruff_logo Black_logo

Ruff Flake8 Pydocstyle MyPy

Installation

pip install torch-cpa

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
pca_model = PCA(n_components=None, whiten=False)

# Use like sklearn.decomposition.PCA
>>> new_X1 = pca_model.fit_transform(X1)
>>> new_X2 = pca_model.transform(X2)
>>> print(pca.explained_variance_ratio_)
[0.756, 0.142, 0.062, ...]

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)

To be implemented

  • Find number of components with explaned variance proportion
  • Randomized SVD solver
  • ARPACK solver
  • Find number of components with MLE
  • inverse_transform method
  • get_covariance method
  • get_precision 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

torch_pca-0.0.3.tar.gz (28.9 kB view hashes)

Uploaded Source

Built Distribution

torch_pca-0.0.3-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page