【问题标题】:how to keep records information when working in ML在 ML 中工作时如何保留记录信息
【发布时间】:2017-12-05 08:09:24
【问题描述】:

我是根据this 提出这个问题的。 OP 说“这个问题在 ML 中不存在,因为它使用 DataFrame,我可以简单地将带有分数的另一列添加到我的原始数据框中。”谁能告诉我该怎么做? 我试过了:

val labeledData = data1.select("labels","hash-tfidf").rdd.map { row =>
  LabeledPoint(row.getAs[Double]("labels"), row.getAs[org.apache.spark.ml.linalg.SparseVector]("hash-tfidf"))
}

val scoreDF = model.transform(labeledData.toDS)

val dfPredictions = data1.withColumn("prediction", scoreDF.col("prediction"))

其中 data1 是我的原始数据框,有很多列。 此错误与:

org.apache.spark.sql.AnalysisException: resolved attribute(s) prediction#1458 missing from ....[loads of fields I think from data1]...

我做错了什么?

【问题讨论】:

    标签: scala apache-spark


    【解决方案1】:

    您不需要RDDs,也不需要LabeledPoint,并且您不能从另一个DataFrame 添加列。

    不清楚model 是什么,但我假设它的输入列是features,因此您可以重命名该列:

    model.transform(data1.withColumnRenamed("hash-tfidf", "features"))
    

    或将model 配置为接受hash-tfidf 作为输入。

    【讨论】:

      猜你喜欢
      • 2016-10-26
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 2023-03-25
      • 2021-03-24
      相关资源
      最近更新 更多