我试图在r中使用kmeans进行聚类,但它会出错
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In storage.mode(x) <- "double" : NAs introduced by coercion
这是代码
Cluster_df <- kmeans(cluster_data, 2, algorithm = "Forgy")
也试过
Cluster_df <- kmeans(cluster_data, 2, algorithm = "Lloyd")
这是数据集
> dput(cluster_data)
structure(list(Value = c(1.2, 40.8, 3.7, 39.5, 2.3, 10.8, 1,
1.2, 0.1, 0.1, 0), Type = c("1 rk", "1 bhk", "1.5 bhk", "2 bhk",
"2.5 bhk", "3 bhk", "3.5 bhk", "4 bhk", "4.5 bhk", "5 bhk", "5.5 bhk"
)), .Names = c("Value", "Type"), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -11L), spec = structure(list(cols = structure(list(
Value = structure(list(), class = c("collector_double", "collector"
)), Type = structure(list(), class = c("collector_character",
"collector"))), .Names = c("Value", "Type")), default = structure(list(), class = c("collector_guess",
"collector"))), .Names = c("cols", "default"), class = "col_spec"))
这是我正在使用的R
的版本
> version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.0
year 2017
month 04
day 21
svn rev 72570
language R
version.string R version 3.4.0 (2017-04-21)
nickname You Stupid Darkness
任何建议都会有所帮助。
感谢。
DOMNICK
答案 0 :(得分:0)
K-means 只能处理连续变量。
否则,它无法计算 mean 。