Class NaiveBayesModel
Object
org.apache.spark.ml.PipelineStage
org.apache.spark.ml.Transformer
org.apache.spark.ml.Model<M>
org.apache.spark.ml.PredictionModel<FeaturesType,M>
org.apache.spark.ml.classification.ClassificationModel<FeaturesType,M>
org.apache.spark.ml.classification.ProbabilisticClassificationModel<Vector,NaiveBayesModel>
org.apache.spark.ml.classification.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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.SparkShellLoggingFilter
-
Method Summary
Modifier and TypeMethodDescriptionCreates a copy of this instance with the same UID and some extra params.static NaiveBayesModel
The model type which is a string (case-sensitive).int
Number of classes (values which the label can take).int
Returns the number of features the model was trained on.pi()
predictRaw
(Vector features) Raw prediction for each possible label.static MLReader<NaiveBayesModel>
read()
sigma()
final DoubleParam
The smoothing parameter.theta()
toString()
uid()
An immutable unique ID for the object and its derivatives.Param for weight column name.write()
Returns anMLWriter
instance for this ML instance.Methods inherited from class org.apache.spark.ml.classification.ProbabilisticClassificationModel
normalizeToProbabilitiesInPlace, predictProbability, probabilityCol, setProbabilityCol, setThresholds, thresholds, transform, transformSchema
Methods inherited from class org.apache.spark.ml.classification.ClassificationModel
predict, rawPredictionCol, setRawPredictionCol, transformImpl
Methods inherited from class org.apache.spark.ml.PredictionModel
featuresCol, labelCol, predictionCol, setFeaturesCol, setPredictionCol
Methods inherited from class org.apache.spark.ml.Transformer
transform, transform, transform
Methods inherited from class org.apache.spark.ml.PipelineStage
params
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.spark.ml.param.shared.HasFeaturesCol
featuresCol, getFeaturesCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasLabelCol
getLabelCol, labelCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasPredictionCol
getPredictionCol, predictionCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasProbabilityCol
getProbabilityCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasRawPredictionCol
getRawPredictionCol, rawPredictionCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasThresholds
getThresholds
Methods inherited from interface org.apache.spark.ml.param.shared.HasWeightCol
getWeightCol
Methods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq
Methods inherited from interface org.apache.spark.ml.util.MLWritable
save
Methods inherited from interface org.apache.spark.ml.classification.NaiveBayesParams
getModelType, getSmoothing
Methods inherited from interface org.apache.spark.ml.param.Params
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
Methods inherited from interface org.apache.spark.ml.classification.ProbabilisticClassifierParams
validateAndTransformSchema
-
Method Details
-
read
-
load
-
smoothing
Description copied from interface:NaiveBayesParams
The smoothing parameter. (default = 1.0).- Specified by:
smoothing
in interfaceNaiveBayesParams
- Returns:
- (undocumented)
-
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 interfaceNaiveBayesParams
- Returns:
- (undocumented)
-
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 interfaceHasWeightCol
- Returns:
- (undocumented)
-
uid
Description copied from interface:Identifiable
An immutable unique ID for the object and its derivatives.- Specified by:
uid
in interfaceIdentifiable
- Returns:
- (undocumented)
-
pi
-
theta
-
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 classPredictionModel<Vector,
NaiveBayesModel>
-
numClasses
public int numClasses()Description copied from class:ClassificationModel
Number of classes (values which the label can take).- Specified by:
numClasses
in classClassificationModel<Vector,
NaiveBayesModel>
-
predictRaw
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 implementtransform()
and outputClassificationModel.rawPredictionCol()
.- Specified by:
predictRaw
in classClassificationModel<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
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. SeedefaultCopy()
.- Specified by:
copy
in interfaceParams
- Specified by:
copy
in classModel<NaiveBayesModel>
- Parameters:
extra
- (undocumented)- Returns:
- (undocumented)
-
toString
- Specified by:
toString
in interfaceIdentifiable
- Overrides:
toString
in classObject
-
write
Description copied from interface:MLWritable
Returns anMLWriter
instance for this ML instance.- Specified by:
write
in interfaceMLWritable
- Returns:
- (undocumented)
-