【发布时间】:2018-12-21 09:12:00
【问题描述】:
这是我使用df.columns 的数据框的结构。
['LastName',
'FirstName',
'Stud. ID',
'10 Relations',
'Related to Politics',
'3NF',
'Documentation & Scripts',
'SQL',
'Data (CSV, etc.)',
'20 Relations',
'Google News',
'Cheated',
'Sum',
'Delay Factor',
'Grade (out of 2)']
我已经使用
在 pyspark 中转换了这个数据框assembler = VectorAssembler(inputCols=['10 Relations',
'Related to Politics',
'3NF'],outputCol='features')
和output = assembler.transform(df)。现在它包含一些 Row 对象。这些对象具有这种架构(这是我运行output.printSchema() 时得到的)
root
|-- LastName: string (nullable = true)
|-- FirstName: string (nullable = true)
|-- Stud. ID: integer (nullable = true)
|-- 10 Relations: integer (nullable = true)
|-- Related to Politics: integer (nullable = true)
|-- 3NF: integer (nullable = true)
|-- Documentation & Scripts: integer (nullable = true)
|-- SQL: integer (nullable = true)
|-- Data (CSV, etc.): integer (nullable = true)
|-- 20 Relations: integer (nullable = true)
|-- Google News: integer (nullable = true)
|-- Cheated: integer (nullable = true)
|-- Sum: integer (nullable = true)
|-- Delay Factor: double (nullable = true)
|-- Grade (out of 2): double (nullable = true)
|-- features: vector (nullable = true)
对于每一行,汇编器选择使特征向量稀疏或密集(出于内存原因)。但这是一个大问题。因为我想使用这些转换后的数据来制作线性回归模型。所以,我正在寻找一种让 VectorAssembler 始终选择密集向量的方法。
有什么想法吗?
注意:我已阅读this post。但问题是,由于 Row 类是 tuple 的子类,所以 Row 对象生成后无法更改。
【问题讨论】: