繁体   English   中英

如何在PySpark中连接两个LabeledPoints的要素列

[英]how to join features columns of two LabeledPoints in PySpark

我有两个LabeledPoints - lable1label2

label1 = (label,[feature1,feature2,feature3])
label2 = (label,[feature4,feature5])

两个LabeledPointslabel列相同,我想形成一个新的LabeledPoint ,其中具有来自两个LabeledPoints feature列连接在一起的功能:

label_new = (label,[feature1,feature2,feature3,feature4,feature5])

如何将两个LabeledPoints在一起?

如您在PySpark的LabeledPoint文档中PySparkLabeledPoint对象具有两个属性labelfeatures ,因此我们可以使用features属性来实现这一点。

from pyspark.mllib.regression import LabeledPoint
import numpy as np

a = LabeledPoint(0, [1,2,3])
b = LabeledPoint(0, [3,1,2])
c = LabeledPoint(a.label, np.concatenate((a.features, b.features), axis=0))

print c # LabeledPoint(0.0, [1.0,2.0,3.0,3.0,1.0,2.0])

注意,您必须注意标签值! 他们可能会有所不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM