【问题标题】:How to merge multiple feature vectors in DataFrame?如何在 DataFrame 中合并多个特征向量?
【发布时间】:2016-01-21 07:12:19
【问题描述】:

使用 Spark ML 转换器,我到达了 DataFrame,其中每一行如下所示:

Row(object_id, text_features_vector, color_features, type_features)

其中text_features 是术语权重的稀疏向量,color_features 是一个小的 20 元素(one-hot-encoder)密集颜色向量,type_features 也是 one-hot-encoder 密集向量类型。

有什么好的方法(使用 Spark 的工具)将这些特征合并到一个大数组中,以便我测量任意两个对象之间的余弦距离之类的东西?

【问题讨论】:

    标签: apache-spark machine-learning apache-spark-sql apache-spark-ml


    【解决方案1】:

    你可以使用VectorAssembler:

    import org.apache.spark.ml.feature.VectorAssembler
    import org.apache.spark.sql.DataFrame
    
    val df: DataFrame = ???
    
    val assembler = new VectorAssembler()
      .setInputCols(Array("text_features", "color_features", "type_features"))
      .setOutputCol("features")
    
    val transformed = assembler.transform(df)
    

    对于 PySpark 示例,请参阅:Encode and assemble multiple features in PySpark

    【讨论】:

      猜你喜欢
      • 2014-07-14
      • 1970-01-01
      • 2016-02-25
      • 2018-03-03
      • 1970-01-01
      • 2013-01-03
      • 2018-01-15
      • 1970-01-01
      • 2015-12-01
      相关资源
      最近更新 更多