R语言K均值聚类:客户数据分析
读取数据
data <- read.csv('data.csv')
选择需要进行聚类的变量
variables <- data[, c('Age', 'Income', 'Family_Quotient')]
进行标准化处理
variables_scaled <- scale(variables)
进行K均值聚类,设定聚类数为3
k_means <- kmeans(variables_scaled, centers = 3)
将聚类结果与原数据合并
data_clustered <- cbind(data, cluster = k_means$cluster)
输出聚类结果
print(data_clustered)
原文地址: https://www.cveoy.top/t/topic/own5 著作权归作者所有。请勿转载和采集!