为什么情节对于相同但缩放的数据表现不同?

时间:2022-10-21 06:36:51

Why does plot behave differently for different data, and how do you control it? My specific example today is getting different output with scaled and non-scaled data. For example

为什么不同数据的情节表现不同,您如何控制它?我今天的具体例子是使用缩放和非缩放数据获得不同的输出。例如

fit <- kmeans(mydata, 4)
plot(mydata, col = fit$cluster)

returns a nice 4x4 scatter matrix plot (mydata is 486x4) but

返回一个漂亮的4x4散点图矩阵(mydata是486x4)但是

mydata <- scale(mydata)
fit <- kmeans(mydata, 4)
plot(mydata, col = fit$cluster)

returns a single plot showing variable 1 scatter plotted vs variable 2?

返回单个图,显示变量1散点图与变量2的关系?

1 个解决方案

#1


1  

This is because scale() returns a matrix rather than a data.frame. Just convert it back to a data.frame

这是因为scale()返回的是矩阵而不是data.frame。只需将其转换回data.frame即可

mydata <- data.frame(scale(mydata))

#1


1  

This is because scale() returns a matrix rather than a data.frame. Just convert it back to a data.frame

这是因为scale()返回的是矩阵而不是data.frame。只需将其转换回data.frame即可

mydata <- data.frame(scale(mydata))