All Bundles

NaiveBayes

Naive Bayes ML algorithm

Operations

Code example:

normal := BayesGroup->New(8.0 / 12.0);
normal->AddEntry(BayesEntry->New("dear", 8));
normal->AddEntry(BayesEntry->New("friend", 5));
normal->AddEntry(BayesEntry->New("lunch", 3));
normal->AddEntry(BayesEntry->New("money", 1));

spam := BayesGroup->New(4.0 / 12.0);
spam->AddEntry(BayesEntry->New("dear", 2));
spam->AddEntry(BayesEntry->New("friend", 1));
spam->AddEntry(BayesEntry->New("lunch", 0));
spam->AddEntry(BayesEntry->New("money", 4));

bayes := NaiveBayes->New(normal, spam);
finding := bayes->Query(["lunch", "money", "money", "money", "money"]);

if(finding = 0) {
  "normal"->PrintLine();
}
else if(finding = 1) {
  "spam"->PrintLine();
}
else {
  "invalid"->PrintLine();
}

New

Constructor

New(left:BayesGroup, right:BayesGroup)
Parameters
NameTypeDescription
leftBayesGroupleft group
rightBayesGroupright group

Query

Query to Naive Bayes

method : public : Query(terms:String[]) ~ Int
Parameters
NameTypeDescription
termsString[]list of term to calculate

Return
TypeDescription
Int0 if left, 1 if right, -1 otherwise