我有一个以下类型的Spark数据集:
org.apache.spark.sql.Dataset[Array[Double]]
我想将数组映射到Vector,以便我可以将它用作ml.clustering.KMeans.fit(...)的输入数据集 . 所以我尝试做这样的事情:
val featureVectors = vectors.map(r => Vectors.dense(r))
但是这失败了以下错误:
error: Unable to find encoder for type stored in a Dataset. Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._ Support for serializing other types will be added in future releases.
我想我需要为 Map 操作指定一个编码器,但我很难找到一种方法来做到这一点 . 有任何想法吗?
1 回答
您需要编码器作为隐式证据:
分解为:
因此,您需要将其传递或隐式提供 .
也就是说,我不相信Vector目前还支持,所以你可能不得不放弃到DataFrame .