Search code examples
pythonvarianceeigenvector

How to obtain standard deviation and proportion of variance from eigenvector eigenvalues


How to obtain standard deviation and proportion of variance from eigenvector eigenvalues ? Il like to implement the calculation in Python.

Thanks


Solution

  • There's an easy way to calculate the relative contribution of each eigenvalue/vector in your data using sklearn in python.

    import numpy as np
    from sklearn.decomposition import PCA
    X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
    pca = PCA(n_components=2)
    pca.fit(X)
    

    the pca object has an attribute called explained variance, which shows the proportion of variance from each eigenvector.

    print(pca.explained_variance_ratio_) 
    

    See http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html for more details.