了解Spark SQL中向量列的表示形式 [英] Understanding Representation of Vector Column in Spark SQL
问题描述
在我使用VectorAssembler()合并一些OneHotEncoded分类功能之前...我的数据框如下所示:
Before I used VectorAssembler() to consolidate some OneHotEncoded categorical features... My data frame looked like so :
| Numerical| HotEncoded1| HotEncoded2
| 14460.0| (44,[5],[1.0])| (3,[0],[1.0])|
| 14460.0| (44,[9],[1.0])| (3,[0],[1.0])|
| 15181.0| (44,[1],[1.0])| (3,[0],[1.0])|
第一列是数字列,其他两列代表OneHotEncoded分类特征的转换数据集.应用VectorAssembler()后,我的输出变为:
The first column is a numerical column and the other two columns represent the transformed data set for OneHotEncoded categorical features. After applying VectorAssembler(), my output becomes:
[(48,[0,1,9],[14460.0,1.0,1.0])]
[(48,[0,3,25],[12827.0,1.0,1.0])]
[(48,[0,1,18],[12828.0,1.0,1.0])]
我不确定这些数字的含义,也无法理解这个转换后的数据集.对此输出的含义进行一些澄清会很棒!
I am unsure of what these numbers mean and cannot make sense of this transformed data set. Some clarification on what this output means would be great!
推荐答案
此输出并非特定于VectorAssembler
.它只是o.a.s.ml.linalg.SparseVector
的字符串表示形式(在Spark< 2.0中为o.a.s.mllib.linalg.SparseVector
),
This output is not specific to VectorAssembler
. It is just a string representation of o.a.s.ml.linalg.SparseVector
(o.a.s.mllib.linalg.SparseVector
in Spark < 2.0) with:
- 代表向量长度的前导数字
- 方括号中的第一组数字是非零索引列表
- 方括号中的第二组数字是与索引相对应的值的列表
所以(48,[0,1,9],[14460.0,1.0,1.0])
表示一个长度为48的向量,具有三个非零的条目:
So (48,[0,1,9],[14460.0,1.0,1.0])
represents a vector of length 48, with three non-zero entries:
- 14460.0位于第0位
- 1.0位于第一个位置
- 1.0位于第9位
几乎相同的描述适用于HotEncoded1
和HotEncoded2
,而Numerical
只是一个标量.如果没有看到元数据和构造函数,就无法说明很多,但是编码变量应该具有44和3或45和4级(取决于dropLast
参数).
Pretty much the same description applies to HotEncoded1
and HotEncoded2
and Numerical
is just a scalar. Without seeing metadata and constructors it is not possible to tell much but encoded variables should have either 44 and 3 or 45 and 4 levels (depending on a dropLast
parameter).
这篇关于了解Spark SQL中向量列的表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!