【问题标题】:Plotting K-means绘制 K 均值
【发布时间】:2018-04-04 02:31:14
【问题描述】:

我正在绘制 K-means,如下所示:

library(dplyr)
library(ggfortify)
newdf <- iris %>% group_by(Species) %>% summarise_each(funs(mean))
set.seed(1)
autoplot(kmeans(newdf, 3), data = newdf)

它给我一个错误:

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

【问题讨论】:

  • 您将“物种”列传递给kmeans,而该列是非数字的。没有明显的方法来计算这样一个变量的距离。这是你的意图吗?你到底想在这里发生什么?

标签: r k-means


【解决方案1】:

请将因子的级别更改为 '0'、'1' 等。取决于因子水平的数量。

那么你就可以避免错误

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 2013-10-20
    • 2012-11-24
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 2013-05-02
    相关资源
    最近更新 更多