Method for (RefLink[Classify, paclet:ref/Classify]).

Determines the class using Bayes's theorem and assuming that features are independent given the class.

Naive Bayes is a classification technique based on Bayes's theorem P(class|x)∝P(class) P(x|class) which assumes that the features x={(Subscript[x, 1]),…,(Subscript[x, n])} are independent given the class. The class probabilities for a given example are then: P(class|x)∝P(class) (∏_(i=1)^n)P((Subscript[x, i])|class), where P ((Subscript[x, i])|class) is the probability distribution of feature (Subscript[x, i]) given the class, and P(class) is the prior probability of the class. Both distributions are estimated from the training data. In the current implementation, distributions are modeled using a piecewise-constant function (i.e a variable-width histogram).

The following suboption can be given

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Train a classifier function on labeled examples:

c=Classify[{1,2,3,4}->{1,1,2,2},Method->"NaiveBayes"]

Obtain information about the classifier:

Information[c]

Classify a new example:

c[1.3]

Generate some normally distributed data:

sampledata[center_]:=RandomVariate[MultinormalDistribution[center,IdentityMatrix[2]],200];

clusters=sampledata/@ {{1.5,1},{-1.5,1},{0,-3}};

Visualize it:

ListPlot[clusters,PlotStyle->Darker@{Yellow,Blue,Green}]

Train a classifier on this dataset:

c=Classify[<|Yellow->clusters[[1]],Blue->clusters[[2]],Green->clusters[[3]]|>, Method->"NaiveBayes"]

Plot the training set and the probability distribution of each class as a function of the features:

Show[
Plot3D[{
c[{x,y},"Probability"->Yellow],c[{x,y},"Probability"->Blue],c[{x,y},"Probability"-> Green]
},{x,-4,4},{y,-5,4}, Exclusions->None],ListPointPlot3D[Map[Append[#,1]&,clusters,{2}], PlotStyle->{Yellow,Blue,Green}]]

OpenersExampleSection1(Spacer1)Options  (2)

OpenersExampleSubsection0(Spacer1)"SmoothingParameter"  (2)

Train a classifier using the "SmoothingParameter" suboption:

Classify[{1,2,3.4,-5,-6}->{"positive","positive","positive","negative","negative"}, 
Method->{"NaiveBayes","SmoothingParameter"->2}]

Train several classifiers on the "FisherIris" dataset by using different settings of the "SmoothingParameter" option:

trainingset=ExampleData[{"MachineLearning", "FisherIris"}, "TrainingData"];

{c1,c2,c3,c4}=Classify[trainingset, Method->{"NaiveBayes","SmoothingParameter"->#}]&/@{.5,20,40,90};

Evaluate these classifiers on a data point that is unlike points from the training set and compare the class probability for class "setosa":

minmaxs=MinMax/@(Transpose[trainingset[[All, 1]]])

#[{4,5,9,-2},"Probability"->"setosa"]&/@{c1,c2,c3,c4}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ClassifierFunction, paclet:ref/ClassifierFunction])  ▪  (RefLink[ClassifierMeasurements, paclet:ref/ClassifierMeasurements])  ▪  (RefLink[Predict, paclet:ref/Predict])  ▪  (RefLink[SequencePredict, paclet:ref/SequencePredict])  ▪  (RefLink[ClusterClassify, paclet:ref/ClusterClassify])  ▪    ▪    ▪    ▪    ▪    ▪    ▪  }, {Related Machine Learning Methods:  (RefLink[DecisionTree, paclet:ref/method/DecisionTree])  ▪  (RefLink[LogisticRegression, paclet:ref/method/LogisticRegression])  ▪  (RefLink[Markov, paclet:ref/method/Markov])  ▪  (RefLink[NearestNeighbors, paclet:ref/method/NearestNeighbors])  ▪  (RefLink[NeuralNetwork, paclet:ref/method/NeuralNetwork])  ▪  (RefLink[RandomForest, paclet:ref/method/RandomForest])  ▪  (RefLink[SupportVectorMachine, paclet:ref/method/SupportVectorMachine])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html])(WebLink[: Machine Learning, https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html])}})}})