gpt4 book ai didi

python - PCA 重建 : statsmodels vs sklearn

转载 作者:太空宇宙 更新时间:2023-11-04 04:01:18 30 4
gpt4 key购买 nike

我正在尝试将我的 PCA 模型从 sklearn 转移到 statmodels。

使用 sklearn,我可以按以下方式重建我的数据:

# reconstruction using 2 principal components
pca = PCA(n_components=2)
pca.fit(X)

# reconstruct the data
X_reconst = np.dot(pca.transform(X)[:,:2], pca.components_[:2,:])

statsmodels 中做同样的事情会怎样?API 和命名法似乎完全不同。

提前致谢!

最佳答案

Statsmodels PCA 实现将数据投影保存为模型属性。

例如,

import statsmodels.api as sm

# specifying two components and fitting data
pca = sm.PCA(X, ncomp=2)
X_reconst = pca.projection

关于python - PCA 重建 : statsmodels vs sklearn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58259871/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com