Apache spark 值序列不是对象贝叶斯的成员

Apache spark 值序列不是对象贝叶斯的成员,apache-spark,machine-learning,Apache Spark,Machine Learning,我是spark的新手,尝试使用文档示例中的MLlib-NaiveBayes。我试图导入NaiveBayes,但我得到以下错误,其中提到它没有train方法。我不知道该怎么做?如果您有任何意见,这将是有益的 import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.mllib.linalg.Vectors import org.apache.spark.mllib.regression.LabeledPoin

我是spark的新手,尝试使用文档示例中的MLlib-NaiveBayes。我试图导入NaiveBayes,但我得到以下错误,其中提到它没有train方法。我不知道该怎么做?如果您有任何意见,这将是有益的

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.classification.NaiveBayes


object NaiveBayes {

def main(args: Array[String]){

val conf = new SparkConf().setMaster("local[1]").setAppName("NaiveBayesExample")
val sc = new SparkContext(conf)

val data = sc.textFile("/Users/Desktop/Studies/sample_naive_bayes_data.txt")
val parsedData = data.map { line =>
  val parts = line.split(',')
  LabeledPoint(parts(0).toDouble, Vectors.dense(parts(1).split(' ').map(_.toDouble)))
}

// Split data into training (60%) and test (40%).
val splits = parsedData.randomSplit(Array(0.6, 0.4), seed = 11L)
val training = splits(0)
val test = splits(1)

val model = NaiveBayes.train(training, lambda = 1.0)

val predictionAndLabel = test.map(p => (model.predict(p.features), p.label))
val accuracy = 1.0 * predictionAndLabel.filter(x => x._1 == x._2).count() / test.count()

println("Accuracy = " + accuracy * 100 + "%")

}
 }
错误:

 Error:(26, 28) value train is not a member of object NaiveBayes
    val model = NaiveBayes.train(training, lambda = 1.0)
                       ^
 Error:(29, 59) value _1 is not a member of Nothing
   val accuracy = 1.0 * predictionAndLabel.filter(x => x._1 == x._2).count() / test.count()
                                                      ^

在您的程序中,您正在重新定义对象
NaiveBayes
,以便spark无法访问mllib对象。
object NaiveBayes
重命名为
object MyNaiveBayes
,以防止出现这种情况。

在您的程序中,您正在重新定义对象
NaiveBayes
,以便spark无法访问mllib对象。 将
object NaiveBayes
重命名为
object MyNaiveBayes
,以防止出现这种情况