Classifier is a simple naive Bayes classifier module for Node.
To install
npm install --save https://github.com/Ocelmot/Classifier.git
To require
const Classifier = require('Classifier');
First generate a classifier instance like so.
var c = Classifier();
Once you have a classifier instance you need to start feeding it evidence. In order to do this you must create an evidence object.
var e = c.Evidence();
You can add information to the evidence object with the add method.
e.add('sale');
If you are training the classifier, you must also add the category to the evidence.
e.setCategory('spam');
To train the classifier, pass the evidence object to the classifier's train method.
c.train(e);
Once you have finished training the classifier, you can classify evidence by passing it to the classify method.
var result = c.classify(e);
console.log(result)
The classify method returns the category name as a string.
- You may repeat the evidence creation, training, and classification as many times as you need.
- You may create multiple classifiers. They will train and classify independently.
- The classifier will automatically add categories as it sees evidence of them.