我被困在一个问题中,我想要做一个PCA在一个Pyspark列。列的名称是“特性”,其中每一行都是一个SparseVector。
这就是流程:
Df - pyspark df的名称
特征-列的名称
rdd的片段
[行(features=SparseVector(2,{1:50.0})]
行(features=SparseVector(2,{0:654.0,1:20.0}))
from pyspark.mllib.linalg.distributed import RowMatrix
i = RowMatrix(df.select(‘features’).rdd)
ipc = i.computePrincipalComponents(2)发布于 2019-11-19 11:09:24
您正在获得一个RDD[Row]对象,您的Row是Row(features=SparseVector(2,{1:50.0}))。
您需要一个RDD[SparseVector],所以您应该更改您的行:
i = RowMatrix(df.select(‘features’).rdd)至
i = RowMatrix(df.select(‘features’).rdd.map(lambda x: x[0]))它将返回RDD[SparseVector]
https://stackoverflow.com/questions/58932169
复制相似问题