【发布时间】:2017-04-21 11:44:52
【问题描述】:
我正在测量 PCA 空间的质心和跨越约 20 个治疗和 3 个组的“特征空间”。如果我正确理解我的数学老师,他们之间的距离应该是相同的。然而,在我计算它们的方式上,它们不是,我想知道我做数学的方式是否是错误的。
我使用臭名昭著的葡萄酒数据集作为我的方法/MWE 的说明:
library(ggbiplot)
data(wine)
treatments <- 1:2 #treatments to be considerd for this calculation
wine.pca <- prcomp(wine[treatments], scale. = TRUE)
#calculate the centroids for the feature/treatment space and the pca space
df.wine.x <- as.data.frame(wine.pca$x)
df.wine.x$groups <- wine.class
wine$groups <- wine.class
feature.centroids <- aggregate(wine[treatments], list(Type = wine$groups), mean)
pca.centroids <- aggregate(df.wine.x[treatments], list(Type = df.wine.x$groups), mean)
pca.centroids
feature.centroids
#calculate distance between the centroids of barolo and grignolino
dist(rbind(feature.centroids[feature.centroids$Type == "barolo",][-1],feature.centroids[feature.centroids$Type == "grignolino",][-1]), method = "euclidean")
dist(rbind(pca.centroids[pca.centroids$Type == "barolo",][-1],pca.centroids[pca.centroids$Type == "grignolino",][-1]), method = "euclidean")
最后两行返回 1.468087 代表特征空间中的距离和 1.80717 代表 pca 空间中的距离,表明美中不足...
【问题讨论】:
标签: r machine-learning distance data-mining pca