无法执行用户定义的函数(VectorAssembler

时间:2019-04-05 13:53:56

标签: scala apache-spark apache-spark-ml

我正在使用Kmeans作为聚类算法,我的代码要执行并显示此错误:

org.apache.spark.SparkException: Failed to execute user defined function(VectorAssembler$$Lambda$1525/671078904: (struct<latitude:double,longitude:double>) => struct<type:tinyint,size:int,indices:array<int>,values:array<double>>)
    at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)

这是数据框代码:

val st = stations
    .withColumn("longitude", $"longitude".cast(sql.types.DoubleType))
    .withColumn("latitude", $"latitude".cast(sql.types.DoubleType))
val stationVA = new VectorAssembler()
    .setInputCols(Array("latitude","longitude"))
    .setOutputCol("location")
val stationWithLoc =stationVA.transform(st)

println("Assembled columns 'hour', 'mobile', 'userFeatures' to vector column 'location'")
stationWithLoc.select("name", "position").show(false)

stationWithLoc.printSchema()
stationWithLoc.show()

对于该模式,它可以正常工作,但是如果我放映演出,我会遇到问题。

1 个答案:

答案 0 :(得分:0)

对我来说,问题与数据有关, 我正在使用一个csv文件,该文件在行中间有一个新行。更新后。 通过df.head(1)检查数据是否正确读取了所有列。