我误会了吗。这是我的代码
使用sklearn
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn import decomposition
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
pca = decomposition.PCA(n_components=3)
x = np.array([
[0.387,4878, 5.42],
[0.723,12104,5.25],
[1,12756,5.52],
[1.524,6787,3.94],
])
pca.fit_transform(x)
输出:
array([[ -4.25324997e+03, -8.41288672e-01, -8.37858943e-03],
[ 2.97275001e+03, -1.25977271e-01, 1.82476780e-01],
[ 3.62475003e+03, -1.56843494e-01, -1.65224286e-01],
[ -2.34425007e+03, 1.12410944e+00, -8.87390454e-03]])
使用numpy方法
x_std = StandardScaler().fit_transform(x)
cov = np.cov(x_std.T)
ev , eig = np.linalg.eig(cov)
a = eig.dot(x_std.T)
输出量
array([[ 0.06406894, 0.94063993, -1.62373172],
[-0.35357757, 0.7509653 , 0.63365168],
[ 0.29312477, 0.6710958 , 1.11766206],
[-0.00361615, -2.36270102, -0.12758202]])
I have kept all 3 components but it doesnt seem to allow me to retain my original data.
我可以知道为什么会这样吗?
如果我想找回原始矩阵,该怎么办?
我正在使用ipython笔记本,因此只能按单元复制。我的数学错了吗?哪一部分@ Anony-Mousse
—
aceminer
@ Anony-Mousse是的,我意识到我的错误,但是仍然不匹配
—
aceminer
@aceminer我很好奇为什么要计算x_std.T而不是x_std的协方差矩阵?
—
叶夫根尼·纳博科夫
@EvgeniNabokov太久了。
—
对不起,
X
未定义的代码)。重新检查数学。