我正在经历一种非常奇怪的行为VectorAssembler,我想知道是否有其他人看过这个.
我的场景很简单.我从一个CSV文件解析数据,我有一些标准Int和Double字段,我还计算一些额外的列.我的解析函数返回:
val joined = countPerChannel ++ countPerSource //two arrays of Doubles joined
(label, orderNo, pageNo, Vectors.dense(joinedCounts))
Run Code Online (Sandbox Code Playgroud)
我的main函数使用解析函数,如下所示:
val parsedData = rawData.filter(row => row != header).map(parseLine)
val data = sqlContext.createDataFrame(parsedData).toDF("label", "orderNo", "pageNo","joinedCounts")
Run Code Online (Sandbox Code Playgroud)
然后我用VectorAssembler这样的:
val assembler = new VectorAssembler()
.setInputCols(Array("orderNo", "pageNo", "joinedCounts"))
.setOutputCol("features")
val assemblerData = assembler.transform(data)
Run Code Online (Sandbox Code Playgroud)
因此,当我在进入数据之前打印一行数据时,VectorAssembler它看起来像这样:
[3.2,17.0,15.0,[0.0,0.0,0.0,0.0,3.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,4.0,0.0,0.0,2.0]]
Run Code Online (Sandbox Code Playgroud)
在VectorAssembler的转换函数之后,我打印同一行数据并得到:
[3.2,(18,[0,1,6,9,14,17],[17.0,15.0,3.0,1.0,4.0,2.0])]
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?做了VectorAssembler什么?我已经仔细检查了所有计算,甚至按照简单的Spark示例,看不出我的代码有什么问题.你能?