MTX_PCA - Principal Component Analysis - non-storing individual observations version
Thu procedure performs a Principal Component Analysis (PCA) using data stored in a matrix.
Usage
The MTX_PCA stored procedure has the following syntax:
- MTX_PCA(modelName,dataMatrixName,forceSufficientStats,centerData,scaleData
- Parameters
- modelName
- The name of the created model.
- dataMatrixName
- The name of the matrix containing the data.
- forceSufficientStats
- Specifies whether the PCA should be based on a covariance matrix even if SVD can be performed.
- centerData
- Specifies whether the model should include data centering, that is, subtraction of the mean estimator.
- scaleData
- Specifies whether the model should include data scaling, which is division by a non-zero standard deviation estimator. When data scaling is performed the resulting PCA model is equivalent to a model based on the correlation matrix.
Details
This procedure directly calls the BOOLEAN = nzm..mtx_PCA(NVARCHAR(ANY) modelName, NVARCHAR(ANY) dataMatrixName, BOOLEAN forceSufficientStats, BOOLEAN centerData, BOOLEAN scaleData, BOOLEAN saveScores) PCA variant with the saveScores input parameter set to FALSE.
Examples
call nzm..shape('1,2,3,4,5,6,7,8,9',1,3,'PCA_TEST');
call nzm..shape('9,8,7,6,5,4,3,2,1',10,1,'PCA_TEST_SOURCE_PRE');
---expected value is 0.0
call nzm..SCALAR_OPERATION('PCA_TEST_SOURCE_PRE',
'PCA_TEST_SOURCE', '-', 0.5);
call nzm..gemm('PCA_TEST_SOURCE','PCA_TEST','PCA_TEST_VALS');
call nzm..mtx_pca('PCA_TEST_MOD','PCA_TEST_VALS',FALSE,FALSE,
FALSE);
call nzm..list_matrices();
std dev in each direction (in this example real value of all
components other than the first one should be 0)
call nzm..print('PCA_TEST_MOD_PCA_SDEV');
---projecting on the original value (first column)
call nzm..gemm_large('PCA_TEST_VALS',FALSE,'PCA_TEST_MOD_PCA',
FALSE, 'PCA_TEST_PROJ');
resulting value (first column of PCA_TEST_PROJ) is proportional
to original one (PCA_TEST_VALS):
PCA_TEST_PROJ[1,] ~~PCA_TEST_SOURCE * sqrt(nzm..red_ssq(
'PCA_TEST'))
call nzm..delete_all_matrices();
SHAPE
-------
t
(1 row)
SHAPE
-------
t
(1 row)
SCALAR_OPERATION
------------------
t
(1 row)
GEMM
------
t
(1 row)
MTX_PCA
---------
t
(1 row)
LIST_MATRICES
-------------------------------------------------------------
PCA_TEST
PCA_TEST_MOD_PCA
PCA_TEST_MOD_PCA_SDEV
PCA_TEST_SOURCE
PCA_TEST_SOURCE_PRE
PCA_TEST_VALS
(1 row)
PRINT
------------------------------------------------------------
-- matrix: PCA_TEST_MOD_PCA_SDEV --
22.118368434905
1.4823621419932e-15
4.2901584776278e-16
(1 row)
GEMM_LARGE
------------
t
(1 row)
DELETE_ALL_MATRICES
---------------------
t
(1 row)