Principal component analysis in Python

前端 未结 11 590
情深已故
情深已故 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:22

    If you're working with 3D vectors, you can apply SVD concisely using the toolbelt vg. It's a light layer on top of numpy.

    import numpy as np
    import vg
    
    vg.principal_components(data)
    

    There's also a convenient alias if you only want the first principal component:

    vg.major_axis(data)
    

    I created the library at my last startup, where it was motivated by uses like this: simple ideas which are verbose or opaque in NumPy.

提交回复
热议问题