Python 使用熊猫数据框进行主成分分析
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23282130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:38:11 来源:igfitidea点击:
Principal components analysis using pandas dataframe
提问by user3362813
How can I calculate Principal Components Analysis from data in a pandas dataframe?
如何从熊猫数据框中的数据计算主成分分析?
回答by Akavall
Most sklearnobjects work with pandas
dataframes just fine, would something like this work for you?
大多数sklearn对象都可以pandas
很好地处理数据框,像这样的东西对你有用吗?
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_