PySpark Array <double>不是Array <double>

时间:2019-04-11 18:34:50

标签: apache-spark pyspark apache-spark-ml

我正在运行一个非常简单的Spark(在Databricks上为2.4.0)ML脚本:

from pyspark.ml.clustering import LDA

lda = LDA(k=10, maxIter=100).setFeaturesCol('features')
model = lda.fit(dataset)

但是收到以下错误:

IllegalArgumentException: 'requirement failed: Column features must be of type equal to one of the following types: [struct<type:tinyint,size:int,indices:array<int>,values:array<double>>, array<double>, array<float>] but was actually of type array<double>.'

为什么我的array<double>不是array<double>

以下是架构:

root
 |-- BagOfWords: struct (nullable = true)
 |    |-- indices: array (nullable = true)
 |    |    |-- element: long (containsNull = true)
 |    |-- size: long (nullable = true)
 |    |-- type: long (nullable = true)
 |    |-- values: array (nullable = true)
 |    |    |-- element: double (containsNull = true)
 |-- tokens: array (nullable = true)
 |    |-- element: string (containsNull = true)
 |-- features: array (nullable = true)
 |    |-- element: double (containsNull = true)

1 个答案:

答案 0 :(得分:1)

您可能需要使用矢量汇编器将其转换为矢量形式 from pyspark.ml.feature import VectorAssembler