drcme.spca.spca_zht

drcme.spca.spca_zht(data, K, para, type='predictor', sparse='penalty', use_corr=False, lambda_val=1e-06, max_iter=200, trace=False, eps_conv=0.001)[source]

Perform sparse principal component analysis

This is a Python port of the sparse PCA algorithm of the R elasticnet package (https://cran.r-project.org/web/packages/elasticnet/index.html), based on Zou, Hastie, and Tibshirani (2006).

Parameters
  • data (array) – A sample-by-feature data matrix (if type is “predictor”), or a sample covariance/correlation matrix (if type is “Gram”)

  • K (int) – Number of components

  • para ((K, ) array) – Parameter array. If sparse is “penalty”, para should contain the L1 norm penalty parameters. If sparse is “varnum”, para should contain the number of non-zero sparse loadings that will be obtained by the algorithm.

  • type ({'predictor', 'Gram'}, optional) – If “predictor” (default), data is a data matrix. If “Gram”, data is a covariance/correlation matrix.

  • sparse ({'penalty', 'varnum'}, optional) – If “penalty” (default), para contains the L1 norm penalties. If “varnum”, para contains the desired number of non-zero loadings.

  • lambda (float, optional) – Quadratic penalty parameter

  • use_corr (bool, optional) – Whether to scale the data by the standard deviation

  • max_iter (int, optional) – Maximum number of iterations

  • trace (bool) – Whether to log progress at level INFO

  • eps_conv (float) – Convergence criterion

Returns

Contains the sparse PCA loadings (“loadings”), adjusted percentage of explained variance (“pev”) and total variance of all the predictors (“var_all”)

Return type

dict