How to implement ZCA Whitening? Python

Here is a python function for generating the ZCA whitening matrix: def zca_whitening_matrix(X): “”” Function to compute ZCA whitening matrix (aka Mahalanobis whitening). INPUT: X: [M x N] matrix. Rows: Variables Columns: Observations OUTPUT: ZCAMatrix: [M x M] matrix “”” # Covariance matrix [column-wise variables]: Sigma = (X-mu)’ * (X-mu) / N sigma = np.cov(X, … Read more

Principal component analysis in Python

Months later, here’s a small class PCA, and a picture: #!/usr/bin/env python “”” a small class for Principal Component Analysis Usage: p = PCA( A, fraction=0.90 ) In: A: an array of e.g. 1000 observations x 20 variables, 1000 rows x 20 columns fraction: use principal components that account for e.g. 90 % of the … Read more

MATLAB is running out of memory but it should not be

For a data matrix of size n-by-p, PRINCOMP will return a coefficient matrix of size p-by-p where each column is a principal component expressed using the original dimensions, so in your case you will create an output matrix of size: 1036800*1036800*8 bytes ~ 7.8 TB Consider using PRINCOMP(X,’econ’) to return only the PCs with significant … Read more

Recovering features names of explained_variance_ratio_ in PCA with sklearn

This information is included in the pca attribute: components_. As described in the documentation, pca.components_ outputs an array of [n_components, n_features], so to get how components are linearly related with the different features you have to: Note: each coefficient represents the correlation between a particular pair of component and feature import pandas as pd import … Read more