Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/7568#discussion_r35932155
--- Diff: python/pyspark/ml/classification.py ---
@@ -576,6 +577,119 @@ 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 = sqlContext.createDataFrame([
+ ... 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]))])
+ >>> nb = NaiveBayes(smoothing=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
+ smoothing = Param(Params._dummy(), "smoothing", "The smoothing
parameter, should be >= 0, " +
+ "default is 1.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",
+ smoothing=1.0, modelType="multinomial"):
+ """
+ __init__(self, featuresCol="features", labelCol="label",
predictionCol="prediction",
+ smoothing=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.smoothing = Param(self, "smoothing", "The smoothing
parameter, should be >= 0, " +
+ "default is 1.0")
+ #: param for the model type.
+ self.modelType = Param(self, "modelType", "The model type which is
a string " +
+ "(case-sensitive). Supported options:
multinomial (default) " +
+ "and bernoulli.")
+ self._setDefault(smoothing=1.0, modelType="multinomial")
+ kwargs = self.__init__._input_kwargs
+ self.setParams(**kwargs)
+
+ @keyword_only
+ def setParams(self, featuresCol="features", labelCol="label",
predictionCol="prediction",
+ smoothing=1.0, modelType="multinomial"):
+ """
+ setParams(self, featuresCol="features", labelCol="label",
predictionCol="prediction",
+ smoothing=1.0, modelType="multinomial")
+ Sets params for Naive Bayes.
+ """
+ kwargs = self.setParams._input_kwargs
+ return self._set(**kwargs)
+
+ def _create_model(self, java_model):
+ return NaiveBayesModel(java_model)
+
+ def setLambda(self, value):
--- End diff --
rename to setSmoothing (same for getLambda)
---
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]