Principal component analysis in Python

前端 未结 11 580
情深已故
情深已故 2020-11-30 16:49

I\'d like to use principal component analysis (PCA) for dimensionality reduction. Does numpy or scipy already have it, or do I have to roll my own using numpy.linalg.eigh?<

11条回答
  •  抹茶落季
    2020-11-30 17:28

    You can quite easily "roll" your own using scipy.linalg (assuming a pre-centered dataset data):

    covmat = data.dot(data.T)
    evs, evmat = scipy.linalg.eig(covmat)
    

    Then evs are your eigenvalues, and evmat is your projection matrix.

    If you want to keep d dimensions, use the first d eigenvalues and first d eigenvectors.

    Given that scipy.linalg has the decomposition and numpy the matrix multiplications, what else do you need?

提交回复
热议问题