Principal components analysis using pandas dataframe

后端 未结 1 773
無奈伤痛
無奈伤痛 2021-01-31 08:00

How can I calculate Principal Components Analysis from data in a pandas dataframe?

相关标签:
1条回答
  • 2021-01-31 08:16

    Most sklearn objects work with pandas dataframes just fine, would something like this work for you?

    import pandas as pd
    import numpy as np
    from sklearn.decomposition import PCA
    
    df = pd.DataFrame(data=np.random.normal(0, 1, (20, 10)))
    
    pca = PCA(n_components=5)
    pca.fit(df)
    

    You can access the components themselves with

    pca.components_ 
    
    0 讨论(0)
提交回复
热议问题