Spark 2.2:从文件加载 org.apache.spark.ml.feature.LabeledPoint
Spark 2.2: Load org.apache.spark.ml.feature.LabeledPoint from file
以下代码行将(即将弃用的)mllib.regression.LabeledPoint
从文件加载到 RDD[LabeledPoint]
:
MLUtils.loadLibSVMFile(spark.sparkContext, s"$path${File.separator}${fileName}_data_sparse").repartition(defaultPartitionSize)
我找不到 ml.feature.LabeledPoint
的等价函数,Spark 文档示例中尚未大量使用它。
谁能告诉我相关功能?
使用 ml
包,您无需将数据放入 LabeledPoint
,因为您可以指定 labels/features 在所有 transformations/algorithms 中使用哪些列.例如:
val gbt = new GBTClassifier()
.setLabelCol("label")
.setFeaturesCol("features")
要将 LibSVM
文件加载为数据框,只需执行以下操作:
val df = spark.read.format("libsvm").load(s"$path${File.separator}${fileName}_data_sparse")
这将 return 具有两列的数据框:
The loaded DataFrame has two columns: label containing labels stored as doubles and features containing feature vectors stored as Vectors.
有关详细信息,请参阅 documentation。
以下代码行将(即将弃用的)mllib.regression.LabeledPoint
从文件加载到 RDD[LabeledPoint]
:
MLUtils.loadLibSVMFile(spark.sparkContext, s"$path${File.separator}${fileName}_data_sparse").repartition(defaultPartitionSize)
我找不到 ml.feature.LabeledPoint
的等价函数,Spark 文档示例中尚未大量使用它。
谁能告诉我相关功能?
使用 ml
包,您无需将数据放入 LabeledPoint
,因为您可以指定 labels/features 在所有 transformations/algorithms 中使用哪些列.例如:
val gbt = new GBTClassifier()
.setLabelCol("label")
.setFeaturesCol("features")
要将 LibSVM
文件加载为数据框,只需执行以下操作:
val df = spark.read.format("libsvm").load(s"$path${File.separator}${fileName}_data_sparse")
这将 return 具有两列的数据框:
The loaded DataFrame has two columns: label containing labels stored as doubles and features containing feature vectors stored as Vectors.
有关详细信息,请参阅 documentation。