Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/7568#discussion_r35606322
--- Diff: python/pyspark/ml/classification.py ---
@@ -576,6 +577,115 @@ class GBTClassificationModel(TreeEnsembleModels):
"""
+@inherit_doc
+class NaiveBayes(JavaEstimator, HasFeaturesCol, HasLabelCol,
HasPredictionCol):
+ """
+ Naive Bayes Classifiers.
+
+ >>> from pyspark.sql import Row
+ >>> from pyspark.mllib.linalg import Vectors
+ >>> df = sc.parallelize([
+ ... Row(label=0.0, features=Vectors.dense([0.0, 0.0])),
+ ... Row(label=0.0, features=Vectors.dense([0.0, 1.0])),
+ ... Row(label=1.0, features=Vectors.dense([1.0, 0.0]))]).toDF()
+ >>> nb = NaiveBayes(lambda_=1.0, modelType="multinomial")
+ >>> model = nb.fit(df)
+ >>> model.pi
+ DenseVector([-0.51..., -0.91...])
+ >>> model.theta
+ DenseMatrix(2, 2, [-1.09..., -0.40..., -0.40..., -1.09...], 1)
+ >>> test0 = sc.parallelize([Row(features=Vectors.dense([1.0,
0.0]))]).toDF()
+ >>> model.transform(test0).head().prediction
+ 1.0
+ >>> test1 = sc.parallelize([Row(features=Vectors.sparse(2, [0],
[1.0]))]).toDF()
+ >>> model.transform(test1).head().prediction
+ 1.0
+ """
+
+ # a placeholder to make it appear in the generated doc
+ lambda_ = Param(Params._dummy(), "lambda_", "The smoothing parameter,
should be >= 0.")
+ modelType = Param(Params._dummy(), "modelType", "The model type which
is a string " +
+ "(case-sensitive). Supported options: multinomial
(default) and bernoulli.")
+
+ @keyword_only
+ def __init__(self, featuresCol="features", labelCol="label",
predictionCol="prediction",
+ lambda_=1.0, modelType="multinomial"):
+ """
+ __init__(self, featuresCol="features", labelCol="label",
predictionCol="prediction",
+ lambda_=1.0, modelType="multinomial")
+ """
+ super(NaiveBayes, self).__init__()
+ self._java_obj = self._new_java_obj(
+ "org.apache.spark.ml.classification.NaiveBayes", self.uid)
+ #: param for the smoothing parameter.
+ self.lambda_ = Param(self, "lambda_", "")
--- End diff --
need Param doc for this and modelType
---
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]