我正在尝试使用 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
K-means 可以只处理连续变量。
否则,它无法计算平均值。
上传数据时,使用“row.names = 1”。 例如, 瑞银<- read.csv("UBS.csv", row.names = 1)
看看这是否有帮助,对我有用。