我是spark的新手,正在尝试使用文档示例中的MLlib - NaiveBayes。我试图导入NaiveBayes,但我得到了下面的错误,提到它没有训练方法。我不确定该如何处理这件事?如果您有任何输入,这将是有帮助的。
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()
^发布于 2016-05-01 13:05:16
在您的程序中,您正在重新定义对象NaiveBayes,以便spark不能访问mllib对象。将object NaiveBayes重命名为object MyNaiveBayes以防止出现这种情况。
https://stackoverflow.com/questions/36962767
复制相似问题