【问题标题】:error: overloaded method value "predict" with alternatives / Double does not take parameters错误:使用替代方法重载方法值“预测”/Double 不带参数
【发布时间】:2018-01-17 04:00:01
【问题描述】:

我正在尝试构建一个简单的线性模型来使用 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)
                              ^

如果我从here 这样做,

// 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) }

                  ^

我相信这些步骤是正确的。但我不知道为什么它显示 overloaded method value predict with alternativeDouble 不带参数

【问题讨论】:

    标签: scala apache-spark linear-regression apache-spark-mllib apache-spark-dataset


    【解决方案1】:
    val prediction = model.predict(realout1.map(_.features));
    

    这个很好用。但我不知道这个有多正确。任何建议表示赞赏。谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 2018-05-17
      • 1970-01-01
      • 2017-08-04
      相关资源
      最近更新 更多