Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/4834#discussion_r25569772
--- Diff: docs/mllib-naive-bayes.md ---
@@ -115,22 +115,31 @@ used for evaluation and prediction.
Note that the Python API does not yet support model save/load but will in
the future.
-<!-- TODO: Make Python's example consistent with Scala's and Java's. -->
{% highlight python %}
-from pyspark.mllib.regression import LabeledPoint
from pyspark.mllib.classification import NaiveBayes
+from pyspark.mllib.linalg import Vectors
+from pyspark.mllib.regression import LabeledPoint
+
+data = sc.textFile("data/mllib/sample_naive_bayes_data.txt")
+
+# Preprocessing
+splitData = data.map(lambda line: line.split(','))
+parsedData = splitData.map(
--- End diff --
We can define a parse function to make the code more readable. Btw, we use
4 space indentation in Python, following PEP8.
~~~python
def parseLine(line):
parts = line.split(',')
label = float(parts[0])
features = Vector.dense([float(x) for x in parts[1].split(' ')])
return LabeledPoint(label, features)
data = sc.textFile('data/mllib/sample_naive_bayes_data.txt').map(parseLine)
~~~
---
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.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]