NaiveBayesModel (Spark 3.5.5 JavaDoc) (original) (raw)
Object
- org.apache.spark.mllib.classification.NaiveBayesModel
All Implemented Interfaces:
java.io.Serializable, ClassificationModel, Saveable
public class NaiveBayesModel
extends Object
implements ClassificationModel, scala.Serializable, Saveable
Model for Naive Bayes Classifiers.
param: labels list of labels param: pi log of class priors, whose dimension is C, number of labels param: theta log of class conditional probabilities, whose dimension is C-by-D, where D is number of features param: modelType The type of NB model to fit can be "multinomial" or "bernoulli"
See Also:
Serialized Form
Nested Class Summary
Nested Classes
Modifier and Type Class and Description static class NaiveBayesModel.SaveLoadV1_0$ static class NaiveBayesModel.SaveLoadV2_0$ Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method and Description double[] labels() static NaiveBayesModel load(SparkContext sc, String path) String modelType() double[] pi() RDD predict(RDD<Vector> testData) Predict values for the given data set using the model trained. double predict(Vector testData) Predict values for a single data point using the model trained. RDD<Vector> predictProbabilities(RDD<Vector> testData) Predict values for the given data set using the model trained. Vector predictProbabilities(Vector testData) Predict posterior class probabilities for a single data point using the model trained. void save(SparkContext sc, String path) Save this model to the given path. double[][] theta() * ### Methods inherited from class Object `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait` * ### Methods inherited from interface org.apache.spark.mllib.classification.[ClassificationModel](../../../../../org/apache/spark/mllib/classification/ClassificationModel.html "interface in org.apache.spark.mllib.classification") `[predict](../../../../../org/apache/spark/mllib/classification/ClassificationModel.html#predict-org.apache.spark.api.java.JavaRDD-)`
Method Detail
* #### load public static [NaiveBayesModel](../../../../../org/apache/spark/mllib/classification/NaiveBayesModel.html "class in org.apache.spark.mllib.classification") load([SparkContext](../../../../../org/apache/spark/SparkContext.html "class in org.apache.spark") sc, String path) * #### labels public double[] labels() * #### pi public double[] pi() * #### theta public double[][] theta() * #### modelType public String modelType() * #### predict public [RDD](../../../../../org/apache/spark/rdd/RDD.html "class in org.apache.spark.rdd")<Object> predict([RDD](../../../../../org/apache/spark/rdd/RDD.html "class in org.apache.spark.rdd")<[Vector](../../../../../org/apache/spark/mllib/linalg/Vector.html "interface in org.apache.spark.mllib.linalg")> testData) Predict values for the given data set using the model trained. Specified by: `[predict](../../../../../org/apache/spark/mllib/classification/ClassificationModel.html#predict-org.apache.spark.rdd.RDD-)` in interface `[ClassificationModel](../../../../../org/apache/spark/mllib/classification/ClassificationModel.html "interface in org.apache.spark.mllib.classification")` Parameters: `testData` \- RDD representing data points to be predicted Returns: an RDD\[Double\] where each entry contains the corresponding prediction * #### predict public double predict([Vector](../../../../../org/apache/spark/mllib/linalg/Vector.html "interface in org.apache.spark.mllib.linalg") testData) Predict values for a single data point using the model trained. Specified by: `[predict](../../../../../org/apache/spark/mllib/classification/ClassificationModel.html#predict-org.apache.spark.mllib.linalg.Vector-)` in interface `[ClassificationModel](../../../../../org/apache/spark/mllib/classification/ClassificationModel.html "interface in org.apache.spark.mllib.classification")` Parameters: `testData` \- array representing a single data point Returns: predicted category from the trained model * #### predictProbabilities public [RDD](../../../../../org/apache/spark/rdd/RDD.html "class in org.apache.spark.rdd")<[Vector](../../../../../org/apache/spark/mllib/linalg/Vector.html "interface in org.apache.spark.mllib.linalg")> predictProbabilities([RDD](../../../../../org/apache/spark/rdd/RDD.html "class in org.apache.spark.rdd")<[Vector](../../../../../org/apache/spark/mllib/linalg/Vector.html "interface in org.apache.spark.mllib.linalg")> testData) Predict values for the given data set using the model trained. Parameters: `testData` \- RDD representing data points to be predicted Returns: an RDD\[Vector\] where each entry contains the predicted posterior class probabilities, in the same order as class labels * #### predictProbabilities public [Vector](../../../../../org/apache/spark/mllib/linalg/Vector.html "interface in org.apache.spark.mllib.linalg") predictProbabilities([Vector](../../../../../org/apache/spark/mllib/linalg/Vector.html "interface in org.apache.spark.mllib.linalg") testData) Predict posterior class probabilities for a single data point using the model trained. Parameters: `testData` \- array representing a single data point Returns: predicted posterior class probabilities from the trained model, in the same order as class labels * #### save public void save([SparkContext](../../../../../org/apache/spark/SparkContext.html "class in org.apache.spark") sc, String path) Description copied from interface: `[Saveable](../../../../../org/apache/spark/mllib/util/Saveable.html#save-org.apache.spark.SparkContext-java.lang.String-)` Save this model to the given path. This saves: - human-readable (JSON) model metadata to path/metadata/ - Parquet formatted data to path/data/ The model may be loaded using `Loader.load`. Specified by: `[save](../../../../../org/apache/spark/mllib/util/Saveable.html#save-org.apache.spark.SparkContext-java.lang.String-)` in interface `[Saveable](../../../../../org/apache/spark/mllib/util/Saveable.html "interface in org.apache.spark.mllib.util")` Parameters: `sc` \- Spark context used to save model data. `path` \- Path specifying the directory in which to save this model. If the directory already exists, this method throws an exception.