wv
Weighted Principal Component Analysis using Expectation Maximization
To install: pip install wv
Overview
The wv package offers a sophisticated approach to Principal Component Analysis (PCA) through the implementation of Weighted Expectation Maximization PCA (EMPCA). This method is particularly useful for handling datasets with noisy or incomplete entries, as it allows for the incorporation of weights that can vary across observations and variables. This package provides tools not only for EMPCA but also includes implementations for classic PCA and a lower rank matrix approximation method, both of which can be used for comparative analysis.
Key Features
- Weighted EMPCA: Iteratively solves PCA with weighted data, ideal for datasets with missing or uncertain values.
- Classic PCA: A straightforward implementation of PCA using Singular Value Decomposition (SVD), without support for weighted data.
- Lower Rank Matrix Approximation: An alternative method that iteratively approximates data using a set of model vectors that are not necessarily orthonormal.
- Model Inspection: After computation, users can inspect eigenvectors, coefficients, and reconstructed models to analyze the principal components and the variance explained by them.
Installation
To install the package, use the following pip command:
pip install wv
Usage
Weighted EMPCA
To perform Weighted EMPCA on your data, you can use the empca function. Here is an example of how to use it:
import numpy as np
from wv import empca
# Example data and weights
data = np.random.normal(size=(100, 10))
weights = np.ones_like(data) # Equal weights
weights[data < 0] = 0.5 # Lower weight for negative values
# Perform EMPCA
model = empca(data, weights, niter=10, nvec=3)
# Access the eigenvectors and model data
eigenvectors = model.eigvec
reconstructed_data = model.model
Classic PCA
For datasets without the need for weighting, you can use the classic_pca function:
from wv import classic_pca
# Example data
data = np.random.normal(size=(100, 10))
# Perform classic PCA
model = classic_pca(data)
# Eigenvectors
eigenvectors = model.eigvec
Lower Rank Matrix Approximation
This method is useful for datasets where the goal is to approximate the data without necessarily obtaining orthonormal vectors:
from wv import lower_rank
# Example data and weights
data = np.random.normal(size=(100, 10))
weights = np.ones_like(data)
# Perform lower rank approximation
model = lower_rank(data, weights, niter=10, nvec=3)
# Model vectors
model_vectors = model.eigvec
Documentation
Classes and Functions
Model
A class for storing the results of PCA computations. It includes the following attributes:
eigvec: Eigenvectors of the model.data: Original data used in the model.weights: Weights applied to the data.coeff: Coefficients to reconstruct the data using the eigenvectors.model: Reconstructed data using the eigenvectors and coefficients.
empca
Function to perform Weighted EMPCA. Parameters include:
data: Data matrix.weights: Corresponding weights matrix.niter: Number of iterations for the EM algorithm.nvec: Number of eigenvectors to compute.smooth: Optional smoothing parameter.randseed: Seed for the random number generator.
classic_pca
Function to perform classic PCA using SVD. It only requires the data matrix and optionally the number of eigenvectors.
lower_rank
Function for lower rank matrix approximation. Similar to empca but does not enforce orthonormality of the resulting vectors.
Additional Tools
SavitzkyGolay: A utility class for smoothing signals using the Savitzky-Golay filter. Useful for preprocessing data or smoothing eigenvectors in the context of PCA.
Contributing
Contributions to the wv package are welcome. Please ensure that any pull requests or issues are clear and reproducible.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for wv 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wv-0.0.7.tar.gz | 12.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wv-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.8 kB
Release files / wv-0.0.7.tar.gz
| Download URL | wv-0.0.7.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e9c0e1d5de1db0b3c79470a8cd74fa79b42a5abdf280cda1984af7d479f2a1e
|
|
BLAKE2b-256 checksum How to use checksums |
48d22d8e0b45932d48c028ef301a54d0d1753c91b743ca049e92123ff41ed97e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wv-0.0.7-py3-none-any.whl
| Download URL | wv-0.0.7-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e95ab515ae60d5058e695a6faa6ef4c32d10d92e36614cff268a6c71df4db2cd
|
|
BLAKE2b-256 checksum How to use checksums |
1a9b1b924fa96b40d58f9efb67aef58ddcc405caad0ca180b1cac8e2b130eea5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|