![]() | SQXPrincipalComponentAnalysisTable Method |
Namespace: sqx
public static IEnumerator PrincipalComponentAnalysisTable( Matrix A )
use [SQX] go -- Your query here. (Numeric fields only) declare @Query nvarchar(max) = N' select MyField1, MyField2, MyField3, MyFieldN from MyDB.dbo.MyTable ' declare @M sqx.Vector, @V sqx.Vector, @Cor sqx.Matrix declare @Rotation int, @EIGENVECTORS sqx.Matrix , @EIGENVALUES sqx.Vector, @VAREXPLAINED sqx.Vector exec sqx.MeanVarCorMatrix @Query = @Query, @Population = 1, @SnapShot = 0 , @Means = @M OUTPUT, @Vars = @V OUTPUT, @Cor = @Cor OUTPUT select @V = @V.Sqrt(), @Rotation = pcat.Rotations , @EIGENVECTORS = pcat.EigenVectors, @EIGENVALUES = pcat.EigenValues , @VAREXPLAINED = pcat.VarianceExplained from sqx.PrincipalComponentAnalysisTable(@Cor) pcat -- Show Results print '** Correlation Matrix' exec sqx.MatrixToTable @Cor print '** Means, StDevs, Eigen Values and Variance Explained' select m.ID FieldNumber, m.Value Mean, s.Value [StDev] , a.[Value] [EigenValue], b.[Value] [VarianceExplained] from sqx.VectorTable(@M) m inner join sqx.VectorTable(@V) s on m.ID = s.ID inner join sqx.VectorTable(@EIGENVALUES) a on m.ID = a.ID inner join sqx.VectorTable(@VAREXPLAINED) b on m.[ID] = b.[ID] order by b.[Value] desc print '** Eigen Vectors' exec sqx.MatrixToTable @EIGENVECTORS