sparklyr ml_kmeans 字段 "features" 不存在

sparklyr ml_kmeans Field "features" does not exist

AWS EC2 Spark / Hadoop 集群。

以下 baisc K-Means sparklyr 代码适用于 Spark 2.0.1

  kmeans_model <- iris_tbl %>%
  select(Petal_Width, Petal_Length) %>%
  ml_kmeans(centers = 3)

我已经升级到 Spark 2.1.1,但出现此错误

    Error: java.lang.IllegalArgumentException: Field "features" does not exist.
        at org.apache.spark.sql.types.StructType$$anonfun$apply.apply(StructType.scala:264)
        at org.apache.spark.sql.types.StructType$$anonfun$apply.apply(StructType.scala:264)
 ...
io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)

我用代码做了一些测试

kmeans_model <- iris_tbl %>%
  select(Petal_Width, Petal_Length) %>%
  ml_kmeans(k = 3, features = c("Petal_Length", "Petal_Width"))

kmeans_model <- iris_tbl %>%
  dplyr::select(Petal_Width, Petal_Length) %>%
  ml_kmeans(centers = 3, features = c("Petal_Length", "Petal_Width"))

但还是报同样的错误

此代码无法在 Spark 2.0 中运行,就像在更新版本中无法运行一样。此代码的应用程序不正确,与 Spark 版本无关。默认情况下 ml_kmeans(和其他 ml_* 函数),期望 Vector 类型列名为 featuresfeatures 可用于覆盖名称,应为:

a length-one character vector

在不使用 ft_vector_assembler 的情况下使其工作的唯一方法是提供 formula:

kmeans_model <- iris_tbl %>% 
  ml_kmeans(formula= ~ Petal_Width + Petal_Length, k = 3)