Github user srowen commented on a diff in the pull request: https://github.com/apache/spark/pull/653#discussion_r12346699 --- Diff: docs/mllib-naive-bayes.md --- @@ -58,29 +67,36 @@ optionally smoothing parameter `lambda` as input, and output a can be used for evaluation and prediction. {% highlight java %} +import org.apache.spark.api.java.JavaPairRDD; +import org.apache.spark.api.java.JavaRDD; +import org.apache.spark.api.java.function.Function; import org.apache.spark.mllib.classification.NaiveBayes; +import org.apache.spark.mllib.classification.NaiveBayesModel; +import org.apache.spark.mllib.regression.LabeledPoint; +import scala.Tuple2; JavaRDD<LabeledPoint> training = ... // training set JavaRDD<LabeledPoint> test = ... // test set -NaiveBayesModel model = NaiveBayes.train(training.rdd(), 1.0); +final NaiveBayesModel model = NaiveBayes.train(training.rdd(), 1.0); -JavaRDD<Double> prediction = model.predict(test.map(new Function<LabeledPoint, Vector>() { --- End diff -- @mengxr Doesn't work unfortunately. You won't be able to cast `Foo<Object>` to `Foo<String>` in Java in general and it doesn't compile for me. I feel like I'm missing something and would like to figure it out; there may be some tweak needed on the Scala side? But at least for here, the snippet proposed in this PR does compile and work and isn't too different.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---