简体   繁体   English

如何在 PCA 之后使用 2 个矩阵重建 Python 中 10 个分量的数据?

[英]How to reconstruct data from 10 components in Python using 2 matrixes after PCA?

Help please,.请帮忙,。 I've seen some anawers here, but they didn't help me.我在这里看到了一些答案,但他们没有帮助我。 I need to reconstruct the initial data.我需要重建初始数据。 having 2 matrixes and using first ten principal components.有 2 个矩阵并使用前十个主成分。 First matrix (Z) (X_reduced_417)- result of applying sklearn.decomposition.PCA.第一个矩阵 (Z) (X_reduced_417) - 应用 sklearn.decomposition.PCA 的结果。 Second matrix (X_loadings_417) (F) is weight matrix?第二个矩阵 (X_loadings_417) (F) 是权重矩阵? Answer is Initial data = Z*F+mean_matrix.答案是初始数据 = Z*F+mean_matrix。 How to use sklearn to find Z?如何使用sklearn找到Z?

import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import sklearn.datasets, sklearn.decomposition

df_loadings = pd.read_csv('X_loadings_417.csv', header=None)
df_reduced = pd.read_csv('X_reduced_417.csv', header=None) ```
import pandas as pd
import numpy as np

# Load the df_loadings and df_reduced matrices from the CSV files
df_loadings = pd.read_csv("X_loadings_417.csv", header=None)
df_reduced = pd.read_csv("X_reduced_417.csv", header=None)

# Convert the DataFrames to numpy arrays
F = df_loadings.values
Z = df_reduced.values

# The mean of the original data is needed to reconstruct the data
mean_matrix = np.mean(X, axis=0)

# Reconstruct the original data using the first ten principal components
X_reconstructed = Z[:,:10].dot(F[:10,:]) + mean_matrix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM