Python Forum
how to do Principal Components Analysis of a Matrix
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to do Principal Components Analysis of a Matrix
#1
I need to do Principal Components (PC) Analysis of a Matrix (X). PC need to be chosen as V(:,end-1,end). May I ask what's mean by "PC is chosen as V(:,end-1,end)" and how to do PC?

I have found eigen value and vector for transpose of X multiple X (XTX), here is my code (using python(x,y) 2.10.7.0):

import numpy as np
X=np.matrix(Xtrain)
print("X")
print(X)
XT=X.transpose()
XTX=np.dot(X,XT)
print('XTX')
print(XTX) 

from numpy import linalg as LA
w,v= LA.eig(XTX)
print('eigen values ')
print(w)
print('eigen vector ')
print(v)

#PCA
from sklearn.decomposition import PCA

def pca2(XTX, pc_count = None):
    return PCA(n_components = 4).fit_transform(XTX)
after running, "ImportError: No module named sklearn.decomposition" is shown. What's the reason? Many thanks for help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  define a diagonal matrix from a matrix amalalaoui 1 2,359 May-15-2019, 01:12 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020