以下代码行将(即将弃用)mllib.regression.LabeledPoint
从文件加载到 RDD[LabeledPoint]
:
MLUtils.loadLibSVMFile(spark.sparkContext, s"$path${File.separator}${fileName}_data_sparse").repartition(defaultPartitionSize)
我无法找到 ml.feature.LabeledPoint
的等效函数,该函数在 Spark 文档示例中尚未大量使用。
有人可以指点我相关的功能吗?
最佳答案
使用 ml
包,您无需将数据放入 LabeledPoint
中,因为您可以指定在所有转换/算法中用于标签/特征的列。例如:
val gbt = new GBTClassifier()
.setLabelCol("label")
.setFeaturesCol("features")
<小时/>
要将 LibSVM
文件作为数据帧加载,只需执行以下操作:
val df = spark.read.format("libsvm").load(s"$path${File.separator}${fileName}_data_sparse")
这将返回一个包含两列的数据框:
The loaded DataFrame has two columns: label containing labels stored as doubles and features containing feature vectors stored as Vectors.
请参阅documentation了解更多信息。
关于scala - Spark 2.2 : Load org. apache.spark.ml.feature.LabeledPoint 来自文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48898301/