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
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.LogStringContext, 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 NaiveBayesModelThe model type which is a string (case-sensitive).intNumber of classes (values which the label can take).intReturns 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 DoubleParamThe smoothing parameter.theta()toString()uid()An immutable unique ID for the object and its derivatives.Param for weight column name.write()Returns anMLWriterinstance for this ML instance.Methods inherited from class org.apache.spark.ml.classification.ProbabilisticClassificationModel
normalizeToProbabilitiesInPlace, predictProbability, probabilityCol, setProbabilityCol, setThresholds, thresholds, transform, transformSchemaMethods inherited from class org.apache.spark.ml.classification.ClassificationModel
predict, rawPredictionCol, setRawPredictionCol, transformImplMethods inherited from class org.apache.spark.ml.PredictionModel
featuresCol, labelCol, predictionCol, setFeaturesCol, setPredictionColMethods inherited from class org.apache.spark.ml.Transformer
transform, transform, transformMethods inherited from class org.apache.spark.ml.PipelineStage
paramsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.spark.ml.param.shared.HasFeaturesCol
featuresCol, getFeaturesColMethods inherited from interface org.apache.spark.ml.param.shared.HasLabelCol
getLabelCol, labelColMethods inherited from interface org.apache.spark.ml.param.shared.HasPredictionCol
getPredictionCol, predictionColMethods inherited from interface org.apache.spark.ml.param.shared.HasProbabilityCol
getProbabilityColMethods inherited from interface org.apache.spark.ml.param.shared.HasRawPredictionCol
getRawPredictionCol, rawPredictionColMethods inherited from interface org.apache.spark.ml.param.shared.HasThresholds
getThresholdsMethods inherited from interface org.apache.spark.ml.param.shared.HasWeightCol
getWeightColMethods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContextMethods inherited from interface org.apache.spark.ml.util.MLWritable
saveMethods inherited from interface org.apache.spark.ml.classification.NaiveBayesParams
getModelType, getSmoothingMethods 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, shouldOwnMethods inherited from interface org.apache.spark.ml.classification.ProbabilisticClassifierParams
validateAndTransformSchema
-
Method Details
-
read
-
load
-
smoothing
Description copied from interface:NaiveBayesParamsThe smoothing parameter. (default = 1.0).- Specified by:
smoothingin interfaceNaiveBayesParams- Returns:
- (undocumented)
-
modelType
Description copied from interface:NaiveBayesParamsThe model type which is a string (case-sensitive). Supported options: "multinomial", "complement", "bernoulli", "gaussian". (default = multinomial)- Specified by:
modelTypein interfaceNaiveBayesParams- Returns:
- (undocumented)
-
weightCol
Description copied from interface:HasWeightColParam for weight column name. If this is not set or empty, we treat all instance weights as 1.0.- Specified by:
weightColin interfaceHasWeightCol- Returns:
- (undocumented)
-
uid
Description copied from interface:IdentifiableAn immutable unique ID for the object and its derivatives.- Specified by:
uidin interfaceIdentifiable- Returns:
- (undocumented)
-
pi
-
theta
-
sigma
-
numFeatures
public int numFeatures()Description copied from class:PredictionModelReturns the number of features the model was trained on. If unknown, returns -1- Overrides:
numFeaturesin classPredictionModel<Vector,NaiveBayesModel>
-
numClasses
public int numClasses()Description copied from class:ClassificationModelNumber of classes (values which the label can take).- Specified by:
numClassesin classClassificationModel<Vector,NaiveBayesModel>
-
predictRaw
Description copied from class:ClassificationModelRaw 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:
predictRawin 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:ParamsCreates 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:
copyin interfaceParams- Specified by:
copyin classModel<NaiveBayesModel>- Parameters:
extra- (undocumented)- Returns:
- (undocumented)
-
toString
- Specified by:
toStringin interfaceIdentifiable- Overrides:
toStringin classObject
-
write
Description copied from interface:MLWritableReturns anMLWriterinstance for this ML instance.- Specified by:
writein interfaceMLWritable- Returns:
- (undocumented)
-