Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on principal component analysis of a matrix. I have already found the component matrix shown below

A = np.array([[-0.73465832 -0.24819766 -0.32045055]
              [-0.3728976   0.58628043 -0.63433607]
              [-0.72617152  0.53812819 -0.22846634]
              [ 0.34042864 -0.08063226 -0.80064174]
              [ 0.8804307   0.17166265  0.04381426]
              [-0.66313032  0.54576874  0.37964986]
              [ 0.286712    0.68305196  0.21769803]
              [ 0.94651412  0.14986739 -0.06825887]
              [ 0.40699665  0.73202276 -0.08462949]])

I need to perform varimax rotation in this component matrix but could not find the exact method and degree to rotate. Most of the examples are shown in R. However I need the method in python.

share|improve this question

2 Answers

Wikipedea has an example in python here!

share|improve this answer
Actually I was looking for using numpy instead of scipy but thanx anyway. i have already looked into that – Rajsubit 33 mins ago
numpy doesn't have a svd method - you may have to seem if there is the same by another name or in another module. – Steve Barnes 12 mins ago

You can find a lot of examples even with Python. Here is an example I found for Python on Wikipedia:

def varimax(Phi, gamma = 1, q = 20, tol = 1e-6):
from scipy import eye, asarray, dot, sum, svd
p,k = Phi.shape
R = eye(k)
d=0
for i in xrange(q):
    d_old = d
    Lambda = dot(Phi, R)
    u,s,vh = svd(dot(Phi.T,asarray(Lambda)**3 - (gamma/p) * dot(Lambda, diag(diag(dot(Lambda.T,Lambda))))))
    R = dot(u,vh)
    d = sum(s)
    if d/d_old < tol: break
return dot(Phi, R)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.