lib/classificator.js
function Naivebayes(options) {
  // set options object
  this.options = {};
  if (typeof options !== 'undefined') {
    if (!options || typeof options !== 'object' || Array.isArray(options)) {
      throw TypeError(
        `NaiveBayes got invalid 'options': ${options}'. Pass in an object.`
      );
    }
    this.options = options;
  }

  this.tokenizer = this.options.tokenizer || defaultTokenizer;
  this.alpha = this.options.alpha || DEFAULT_ALPHA;
  this.fitPrior = this.options.fitPrior === undefined ? DEFAULT_FIT_PRIOR : this.options.fitPrior;
  // initialize our vocabulary and its size
  this.vocabulary = {};
  this.vocabularySize = 0;

  // number of documents we have learned from
  this.totalDocuments = 0;

  // document frequency table for each of our categories
  //= > for each category, how often were documents mapped to it
  this.docCount = {};

  // for each category, how many words total were mapped to it
  this.wordCount = {};

  // word frequency table for each category
  //= > for each category, how frequent was a given word mapped to it
  this.wordFrequencyCount = {};

  // hashmap of our category names
  this.categories = {};
}
function Naivebayes(options) {
  // set options object
  this.options = {};
  if (typeof options !== 'undefined') {
    if (!options || typeof options !== 'object' || Array.isArray(options)) {
      throw TypeError(
        `NaiveBayes got invalid 'options': ${options}'. Pass in an object.`
      );
    }
    this.options = options;
  }

  this.tokenizer = this.options.tokenizer || defaultTokenizer;
  this.alpha = this.options.alpha || DEFAULT_ALPHA;
  this.fitPrior = this.options.fitPrior === undefined ? DEFAULT_FIT_PRIOR : this.options.fitPrior;
  // initialize our vocabulary and its size
  this.vocabulary = {};
  this.vocabularySize = 0;

  // number of documents we have learned from
  this.totalDocuments = 0;

  // document frequency table for each of our categories
  //= > for each category, how often were documents mapped to it
  this.docCount = {};

  // for each category, how many words total were mapped to it
  this.wordCount = {};

  // word frequency table for each category
  //= > for each category, how frequent was a given word mapped to it
  this.wordFrequencyCount = {};

  // hashmap of our category names
  this.categories = {};
}
function Naivebayes ( options ) { // set options object this . options = { } ; if ( typeof options !== 'undefined' ) { if ( ! options || typeof options !== 'object' || Array . isArray ( options ) ) { throw TypeError ( ` ${ options } ` ) ; } this . options = options ; } this . tokenizer = this . options . tokenizer || defaultTokenizer ; this . alpha = this . options . alpha || DEFAULT_ALPHA ; this . fitPrior = this . options . fitPrior === undefined ? DEFAULT_FIT_PRIOR : this . options . fitPrior ; // initialize our vocabulary and its size this . vocabulary = { } ; this . vocabularySize = 0 ; // number of documents we have learned from this . totalDocuments = 0 ; // document frequency table for each of our categories //= > for each category, how often were documents mapped to it this . docCount = { } ; // for each category, how many words total were mapped to it this . wordCount = { } ; // word frequency table for each category //= > for each category, how frequent was a given word mapped to it this . wordFrequencyCount = { } ; // hashmap of our category names this . categories = { } ; }
Naive-Bayes Classifier

This is a naive-bayes classifier that uses Laplace Smoothing.

Takes an (optional) options object containing:
- `tokenizer`  => custom tokenization function
Naive - Bayes Classifier