理解 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
(o.a.s.mllib.linalg.SparseVector
in Spark <2.0)的字符串表示形式:
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屋!