Class NaiveBayesModel

All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, ClassifierParams, NaiveBayesParams, ProbabilisticClassifierParams, Params, HasFeaturesCol, HasLabelCol, HasPredictionCol, HasProbabilityCol, HasRawPredictionCol, HasThresholds, HasWeightCol, PredictorParams, Identifiable, MLWritable, scala.Serializable

public class NaiveBayesModel extends ProbabilisticClassificationModel<Vector,NaiveBayesModel> implements NaiveBayesParams, MLWritable
Model produced by NaiveBayes

param: pi log of class priors, whose dimension is C (number of classes) param: theta log of class conditional probabilities, whose dimension is C (number of classes) by D (number of features) param: sigma variance of each feature, whose dimension is C (number of classes) by D (number of features). This matrix is only available when modelType is set Gaussian.

See Also:
  • Method Details

    • read

      public static MLReader<NaiveBayesModel> read()
    • load

      public static NaiveBayesModel load(String path)
    • smoothing

      public final DoubleParam smoothing()
      Description copied from interface: NaiveBayesParams
      The smoothing parameter. (default = 1.0).
      Specified by:
      smoothing in interface NaiveBayesParams
      Returns:
      (undocumented)
    • modelType

      public final Param<String> modelType()
      Description copied from interface: NaiveBayesParams
      The model type which is a string (case-sensitive). Supported options: "multinomial", "complement", "bernoulli", "gaussian". (default = multinomial)
      Specified by:
      modelType in interface NaiveBayesParams
      Returns:
      (undocumented)
    • weightCol

      public final Param<String> weightCol()
      Description copied from interface: HasWeightCol
      Param for weight column name. If this is not set or empty, we treat all instance weights as 1.0.
      Specified by:
      weightCol in interface HasWeightCol
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • pi

      public Vector pi()
    • theta

      public Matrix theta()
    • sigma

      public Matrix sigma()
    • numFeatures

      public int numFeatures()
      Description copied from class: PredictionModel
      Returns the number of features the model was trained on. If unknown, returns -1
      Overrides:
      numFeatures in class PredictionModel<Vector,NaiveBayesModel>
    • numClasses

      public int numClasses()
      Description copied from class: ClassificationModel
      Number of classes (values which the label can take).
      Specified by:
      numClasses in class ClassificationModel<Vector,NaiveBayesModel>
    • predictRaw

      public Vector predictRaw(Vector features)
      Description copied from class: ClassificationModel
      Raw prediction for each possible label. The meaning of a "raw" prediction may vary between algorithms, but it intuitively gives a measure of confidence in each possible label (where larger = more confident). This internal method is used to implement transform() and output ClassificationModel.rawPredictionCol().

      Specified by:
      predictRaw in class ClassificationModel<Vector,NaiveBayesModel>
      Parameters:
      features - (undocumented)
      Returns:
      vector where element i is the raw prediction for label i. This raw prediction may be any real number, where a larger value indicates greater confidence for that label.
    • copy

      public NaiveBayesModel copy(ParamMap extra)
      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Model<NaiveBayesModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • toString

      public String toString()
      Specified by:
      toString in interface Identifiable
      Overrides:
      toString in class Object
    • write

      public MLWriter write()
      Description copied from interface: MLWritable
      Returns an MLWriter instance for this ML instance.
      Specified by:
      write in interface MLWritable
      Returns:
      (undocumented)