Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/653#discussion_r12303197
--- 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 --
I was not able to get `NaiveBayes.predict()`'s return type to work here,
even after using `.rdd()` and `toJavaRDD()` and even `new JavaRDD(...)`. The
generic type `Double` always seemed to be lost, due to `ClassTag` voodoo I
imagine. Hence this way. Maybe there was a way to make it work, but this works
fine for the tiny example.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---