我正在尝试将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

10-08 02:39