[Mathematical model] The principal component analysis Method Python implementation

Source: Internet
Author: User
def PCA (Datamat, topnfeat=9999999):            #数据矩阵, output before Topnfeat feat    meanvals = Mean (Datamat, axis=0)           # Calculate Average    meanremoved = datamat-meanvals     Covmat = CoV (meanremoved, rowvar=0)        #计算协方差矩阵    eigvals,eigvects = Linalg.eig (Mat (Covmat)) #特征值,    eigvalind = Argsort (eigvals)               #排序, to find the eigenvalues. In fact, the most inconsistent with other changes    Eigvalind = eigvalind[:-( topnfeat+1): -1]   #反转    redeigvects = eigvects[:,eigvalind]        #    Lowddatamat = meanremoved * Redeigvects    #映射    reconmat = (Lowddatamat * redeigvects.t) + meanvals    return Lowddatamat, Reconmat

The mathematical principle of principal component analysis we can simply look at it: find the most varied direction as a new feature

If you want to infer the meaning of this division from the results of the program, Redeigvects is very critical, and it gives a mapping relationship



[Mathematical model] The principal component analysis Method Python implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.