matlab 中 pca 的系数不是 p*p 矩阵
the coeff of pca in matlab is not a p*p matrix
我的数据矩阵是 X
即 4999*37152
。然后我在 Matlab 中使用这个命令:
[coeff, score, latent, tsquared1, explained1] = pca(X);
输出:coeff
是37152*4998
,score
是4999*4998
,latent
是4998*1
。根据http://www.mathworks.com/help/stats/pca.html,系数应该是p*p。那么我的代码有什么问题呢?
正如 Matlab 文档所说,"Rows of X correspond to observations and columns correspond to variables"。因此,您输入的矩阵只有 4999 个观测值,用于 37152 个观测值。在几何上,您在 37152 维 space 中有 4999 个点。这些点包含在一个 4998 维的仿射子 space 中,因此 Matlab 为您提供了 4998 个方向(每个方向表示为具有 37152 个分量的向量)。
有关更多信息,请参阅统计网站:
- Why are there only n-1 principal components for n data points if the number of dimensions is larger than n?
- PCA when the dimensionality is greater than the number of samples
编写 MATLAB 文档时假设您的观测值至少与变量一样多,这是人们通常使用 PCA 的方式。
当然,有可能你的数据实际上有 4999 个变量的 37152 个观测值,在这种情况下你需要转置 X。
我的数据矩阵是 X
即 4999*37152
。然后我在 Matlab 中使用这个命令:
[coeff, score, latent, tsquared1, explained1] = pca(X);
输出:coeff
是37152*4998
,score
是4999*4998
,latent
是4998*1
。根据http://www.mathworks.com/help/stats/pca.html,系数应该是p*p。那么我的代码有什么问题呢?
正如 Matlab 文档所说,"Rows of X correspond to observations and columns correspond to variables"。因此,您输入的矩阵只有 4999 个观测值,用于 37152 个观测值。在几何上,您在 37152 维 space 中有 4999 个点。这些点包含在一个 4998 维的仿射子 space 中,因此 Matlab 为您提供了 4998 个方向(每个方向表示为具有 37152 个分量的向量)。
有关更多信息,请参阅统计网站:
- Why are there only n-1 principal components for n data points if the number of dimensions is larger than n?
- PCA when the dimensionality is greater than the number of samples
编写 MATLAB 文档时假设您的观测值至少与变量一样多,这是人们通常使用 PCA 的方式。
当然,有可能你的数据实际上有 4999 个变量的 37152 个观测值,在这种情况下你需要转置 X。