xgboost4j - 火花评估需要 RDD[(Double, Double)]

xgboost4j - spark evaluate requires RDD[(Double, Double)]

我尝试将 xgboost4j 与 spark 2.0.1 和数据集一起使用 API。到目前为止,我通过使用 model.transform(testData)

获得了以下格式的预测
predictions.printSchema
root
 |-- label: double (nullable = true)
 |-- features: vector (nullable = true)
 |-- probabilities: vector (nullable = true)
 |-- prediction: double (nullable = true)


+-----+--------------------+--------------------+----------+
|label|            features|       probabilities|prediction|
+-----+--------------------+--------------------+----------+
|  0.0|[0.0,1.0,0.0,476....|[0.96766251325607...|       0.0|
|  0.0|[0.0,1.0,0.0,642....|[0.99599152803421...|       0.0|

但现在我想生成评估指标。如何将预测映射到正确的格式? XGBoost-4j by DMLC on Spark-1.6.1 提出了一个类似的问题,但我无法让它为我工作。

val metrics = new BinaryClassificationMetrics(predictions.select("prediction", "label").rdd)
would require RDD[(Double, Double)] 

而不是 predictions.select("prediction", "label") 看起来像

root
 |-- label: double (nullable = true)
 |-- prediction: double (nullable = true)

尝试将其映射到所需的元组,例如:

predictions.select("prediction", "label").map{case Row(_) => (_,_)}

同样无法正常工作。

编辑

在 sparks 文档中多读了一点,我发现 http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.ml.evaluation.BinaryClassificationEvaluator 它支持 ml 而不是 ml-lib,例如数据集。到目前为止,我无法成功地将 xgboost4j 集成到管道中。

这是一个很好的示例 https://github.com/dmlc/xgboost/blob/master/jvm-packages/xgboost4j-example/src/main/scala/ml/dmlc/xgboost4j/scala/example/spark/SparkModelTuningTool.scala 如何在 spark 管道中使用 xgboost4j。事实上,他们有一个 XGBoostEstimator,它在管道中运行良好。