首页 > 代码库 > R-kmeans

R-kmeans

data <- read.csv("//Users//tangjingxiao//Desktop//2.csv",header=T,sep="\t",encoding="utf-8")datafix(data)View(data)newdata <- t(data)view(newdata)View(newdata)kc <- kmeans(newdata,30)kcplot(newdata,col=kc$cluster)points(kc$centers, col = 1:2, pch = 8, cex = 2)ss <- function(y) sum(scale(y, scale = FALSE)^2)ss## cluster centers "fitted" to each obs.:fitted.newdata <- fitted(kc);head(fitted.newdata);resid.newdata<- newdata - fitted(kc);resid