Gullible
A naive Bayes text classifier in JavaScript.
Installation
The easiest way is to use npm
:
npm install gullible
Alternatively, you can clone the git
repository:
git clone https://github.com/erdiaker/gullible.git
Examples
// Load modulevar Gullible = ; // Create a new classifier instancevar c = ; // Prepare a training set var trainSet = text: 'My name is Ozymandias, king of kings: Look on my works, ye Mighty, and despair!' label: 'ozymandias' text: 'A horse! A horse! My kingdom for a horse!' label: 'edward_iii' ; // Learn some text-class pairsc;c; // Classify a new textvar testText = 'Hey! Wanna trade your horse for my kingdom?';var cls = c;console; // edward_iii // Estimate a score for text-class pairvar scoreEd = c;var scoreOzy = c;console; // true // Unlearn a previously learned sample.c;var cls2 = c;console; // ozymandias // Serialize classifier as a JSON stringvar serialized = Gullible; // Restore serialized classifiervar restored = Gullible;