Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7284#discussion_r34639280
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/classification/NaiveBayes.scala ---
    @@ -0,0 +1,192 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.ml.classification
    +
    +import org.apache.spark.SparkException
    +import org.apache.spark.ml.{PredictorParams, PredictionModel, Predictor}
    +import org.apache.spark.ml.param.{ParamMap, ParamValidators, Param, 
DoubleParam}
    +import org.apache.spark.ml.util.Identifiable
    +import org.apache.spark.mllib.classification.{NaiveBayes => OldNaiveBayes}
    +import org.apache.spark.mllib.classification.{NaiveBayesModel => 
OldNaiveBayesModel}
    +import org.apache.spark.mllib.linalg._
    +import org.apache.spark.mllib.regression.LabeledPoint
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.DataFrame
    +
    +/**
    + * Params for Naive Bayes Classifiers.
    + */
    +private[ml] trait NaiveBayesParams extends PredictorParams {
    +
    +  /**
    +   * The smoothing parameter.
    +   * (default = 1.0).
    +   * @group param
    +   */
    +  final val lambda: DoubleParam = new DoubleParam(this, "lambda", "The 
smoothing parameter.",
    +    ParamValidators.gtEq(0))
    +
    +  /** @group getParam */
    +  final def getLambda: Double = $(lambda)
    +
    +  /**
    +   * The model type which is a string (case-sensitive).
    +   * Supported options: "multinomial" and "bernoulli".
    +   * (default = multinomial)
    +   * @group param
    +   */
    +  final val modelType: Param[String] = new Param[String](this, "modelType",
    +    "The model type which is a string (case-sensitive). Supported options: 
" +
    +    "\"multinomial\" (default) and \"bernoulli\".")
    +
    +  /** @group getParam */
    +  final def getModelType: String = $(modelType)
    +}
    +
    +/**
    + * Naive Bayes Classifiers.
    + * It supports both Multinomial NB
    + * 
([[http://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html]])
    + * which can handle finitely supported discrete data. For example, by 
converting documents into
    + * TF-IDF vectors, it can be used for document classification. By making 
every vector a
    + * binary (0/1) data, it can also be used as Bernoulli NB
    + * 
([[http://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html]]).
    + * The input feature values must be nonnegative.
    + */
    +class NaiveBayes(override val uid: String)
    +  extends Predictor[Vector, NaiveBayes, NaiveBayesModel]
    +  with NaiveBayesParams {
    +
    +  def this() = this(Identifiable.randomUID("nb"))
    +
    +  /**
    +   * Set the smoothing parameter.
    +   * Default is 1.0.
    +   * @group setParam
    +   */
    +  def setLambda(value: Double): this.type = set(lambda, value)
    +  setDefault(lambda -> 1.0)
    +
    +  /**
    +   * Set the model type using a string (case-sensitive).
    +   * Supported options: "multinomial" and "bernoulli".
    +   * Default is "multinomial"
    +   */
    +  def setModelType(value: String): this.type = set(modelType, value)
    +  setDefault(modelType -> "multinomial")
    +
    +  override protected def train(dataset: DataFrame): NaiveBayesModel = {
    +    val oldDataset: RDD[LabeledPoint] = extractLabeledPoints(dataset)
    +    val oldModel = OldNaiveBayes.train(oldDataset, $(lambda), $(modelType))
    +    NaiveBayesModel.fromOld(oldModel, this)
    +  }
    +
    +  override def copy(extra: ParamMap): NaiveBayes = defaultCopy(extra)
    +}
    +
    +/**
    + * Model produced by [[NaiveBayes]]
    + */
    +class NaiveBayesModel private[ml] (
    +    override val uid: String,
    +    val labels: Vector,
    --- End diff --
    
    Could you please remove "labels?"  I realized this is a major inconsistency 
for NaiveBayes.  No other model in mllib or ml includes labels.  In Pipelines, 
this should be handled by StringIndexer beforehand.  Sorry I did not think of 
this before!


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to