dclassify
dclassify is a Naive Bayesian classifier for NodeJS that goes one step further than your usual binary classifier by introducing a unique probablility-of-absence optimisation. In testing this optimisation has led to a ~10% improvement in correctness over conventional binary classifiers. It is mainly intended for classifying items based on a finite set of characteristics, rather than for language processing.
General-purpose Document and DataSet classes are provided for training and test data sets.
If the applyInverse optimisation is used, dclassify will calculate probabilities based on the present tokens as usual, but will also calculate a probability-of-absence for missing tokens. This is unconventional but produces better results particularly when working with smaller vocabularies. Its especially well-suited for classifying items based on a limited set of characteristics.
Installation
npm install dclassify
Usage
- Require the classifier and reference its utilities.
- Create Document instances with names and an array of tokens representing the document's characteristics.
- Add document instances to a DataSet using appropriate categories.
- Create and train a classifier using the DataSet.
- Test the classifier using a test Document.
// module dependenciesvar dclassify = ;// Utilities provided by dclassifyvar Classifier = dclassifyClassifier;var DataSet = dclassifyDataSet;var Document = dclassifyDocument;// create some 'bad' test items (name, array of characteristics)var item1 = 'item1' 'a''b''c';var item2 = 'item2' 'a''b''c';var item3 = 'item3' 'a''d''e';// create some 'good' items (name, characteristics)var itemA = 'itemA' 'c' 'd';var itemB = 'itemB' 'e';var itemC = 'itemC' 'b''d''e';// create a DataSet and add test items to appropriate categories// this is 'curated' data for trainingvar data = ;data;data;// an optimisation for working with small vocabulariesvar options =applyInverse: true;// create a classifiervar classifier = options;// train the classifierclassifier;console;console;// test the classifier on a new test itemvar testDoc = 'testDoc' 'b''d' 'e';var result1 = classifier;console;
Probabilities
The probabilities get calculated like this.
Output
Standard results look like this:
If you use the 'applyInverse' option, the results are much more emphatic, because training indicates bad items never lack the "a" token.