错误:重载的方法值"predict"与替代项/双精度不采用参数



我正在尝试构建一个简单的线性模型来使用LinearRegressionWithSGD预测标签值。 我转换了数据集以获取特征和标签,并再次转换为标记点以进行回归

val train = dftrain.withColumn("label", dftrain("col2")).select("features", "label")
val test = dftest.withColumn("label", dftest("col2")).select("features", "label")
val realout  = train.rdd.map(row => LabeledPoint(row.getAs[Double]("label"),DenseVector.fromML(row.getAs[org.apache.spark.ml.linalg.DenseVector]("features"))))
val realout1  = test.rdd.map(row => LabeledPoint(row.getAs[Double]("label"),DenseVector.fromML(row.getAs[org.apache.spark.ml.linalg.DenseVector]("features"))))

现在我正在拟合模型

val numIterations = 100
val stepSize = 0.00000001
//fitting the model with converted Labeled points Train Data
val model = LinearRegressionWithSGD.train(realout, numIterations, stepSize)
17/08/09 12:16:15 WARN LinearRegressionWithSGD: The input data is not directly c
ached, which may hurt performance if its parent RDDs are also uncached.
17/08/09 12:16:17 WARN BLAS: Failed to load implementation from: com.github.fomm
il.netlib.NativeSystemBLAS
17/08/09 12:16:17 WARN BLAS: Failed to load implementation from: com.github.fomm
il.netlib.NativeRefBLAS
17/08/09 12:16:17 WARN LinearRegressionWithSGD: The input data was not directly
cached, which may hurt performance if its parent RDDs are also uncached.
model: org.apache.spark.mllib.regression.LinearRegressionModel = org.apache.spar
k.mllib.regression.LinearRegressionModel: intercept = 0.0, numFeatures = 1

它给了我一些警告,也给出了Intercept为 0.0,我觉得它不正确。但是当我预测模型时,它会给我带来错误。

val prediction = model.predict(realout1)
<console>:98: error: overloaded method value predict with alternatives:
(testData: org.apache.spark.api.java.JavaRDD[org.apache.spark.mllib.linalg.Vec
tor])org.apache.spark.api.java.JavaRDD[Double] <and>
(testData: org.apache.spark.mllib.linalg.Vector)Double <and>
(testData: org.apache.spark.rdd.RDD[org.apache.spark.mllib.linalg.Vector])org.
apache.spark.rdd.RDD[Double]
cannot be applied to (org.apache.spark.rdd.RDD[org.apache.spark.mllib.regressio
n.LabeledPoint])
val prediction = model.predict(realout1)
^

另外,如果我从这里这样做,

// Evaluate model on training examples and compute training error
val valuesAndPreds = realout.map { point => val prediction = model.predict(point.features) (point.label, prediction) }
<console>:90: error: Double does not take parameters
val valuesAndPreds = realout.map { point => val prediction = model.predic
t(point.features) (point.label, prediction) }
^

我相信这些步骤是正确的。但我不知道为什么它显示带有替代方法值预测的重载方法值或Double 不接受参数

val prediction = model.predict(realout1.map(_.features));

这个工作正常。但我不知道这个有多正确。任何建议不胜感激。谢谢。

最新更新