Principal component analysis of Python remote sensing data

Source: Internet
Author: User

Original: http://www.cnblogs.com/leonwen/p/5158947.html

  The algorithm is ported by MATLAB (see the previous blog post for details). But the final output is inconsistent with MATLAB, it is found that in the invocation of the internal function Eig to solve eigenvalues and eigenvectors, both eigenvalues are consistent, but the eigenvectors are different.

But, theoretically, it makes sense, because eigenvectors are inherently non-unique. The most puzzling thing is that even if the eigenvectors are inconsistent, why is the result of using PCA quite contrasting? It feels like Python's inaccurate line is a little bit bigger.

The code is as follows:

#-*-coding:utf-8-*-"""Created on Tue Jan 12 21:45:57 2016
@author: Text Core"""ImportOS fromPILImportImage fromNumPyImport* fromPylabImport*Path= R'D:\Projects\PythonProj\ImageProcessing\2012'Sst_dir=os.listdir (path) File_len=Len (sst_dir) sst_list= [] forIinchRange (File_len): Str= Path +'\\'+Sst_dir[i]#txt = open (str). Read ()sst_list.append (str) Immatrix= [] forIminchSst_list:text=loadtxt (IM) immatrix.append (text) Immatrix=Array (Immatrix)#Display OutputFigure () Gray () forIinchRange (File_len): Subplot (3,4,i + 1) pic= Immatrix[i].reshape (180,360) pic= Pic[::-1]#picshow = rot90 (pic,4)imshow (pic) Colorbar () show ()#Convert to sample populationX =Immatrix. T#get to this sizeM,n = X.shape[0:2]#obtain the average of each sampleMeanval = mean (X,axis =0)#Tempmean = Tile (Meanval, (64800,1))#Sample matrix de -CentralizedX = X-tile (Meanval, (64800,1))#Calculate covarianceS = dot (x.t,x)/(m-1)#calculate eigenvalues eg and eigenvector evEg,ev =Linalg.eig (S)#eg1,ev1 = Linalg.eigh (S) # There are sorting differences between the two algorithms, Eigh return results from small to large#calculate a new ingredientY =Dot (Immatrix. T,ev) figure () Gray () forIinchrange (N): Subplot (3,4,i + 1) out=Y[:,i]Outpic= Out.reshape (180,360) Outpic= Outpic[::-1]imshow (outpic)Colorbar () show ()

The results show:

Raw Data display

PCA main component Analysis result output

May be my own reason, is being found out, which is the guidance of the Great God of the guidance of the class to give me a little bit ~ First thanked ~o (∩_∩) o~

Python Remote sensing Data principal component analysis

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.