pca

How to display Prince PCA Eigenvectors


I am looking for a way to display the eigenvectors on the prince library. Could you please tell me what is the command as I am not finding it in the documentation (eigenvalues_ for eigenvalues) :)


Solution

  • prince is not able to display eigenvectors. However, you can easily calculate eigenvectors with scikit-learn.

    Here a reproducible example:

    import prince
    import numpy as np
    
    from sklearn import datasets
    from sklearn.preprocessing import StandardScaler
    
    iris = datasets.load_iris()
    X_active = iris.data
    
    scaler = StandardScaler()
    X_active_array = scaler.fit_transform(X_active)
        
    covariance_matrix = np.cov(X_active, rowvar=False) 
    eigenvalues, eigenvectors = np.linalg.eig(covariance_matrix)
    
    print(eigenvectors)
    
    [[ 0.36138659 -0.65658877 -0.58202985  0.31548719]
    [-0.08452251 -0.73016143  0.59791083 -0.3197231 ]
    [ 0.85667061  0.17337266  0.07623608 -0.47983899]
    [ 0.3582892   0.07548102  0.54583143  0.75365743]]