GithubHelp home page GithubHelp logo

hhy5277 / classifier-2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harthur/classifier

0.0 2.0 0.0 169 KB

[UNMAINTAINED] Bayesian classifier with Redis backend

License: MIT License

JavaScript 100.00%

classifier-2's Introduction

Deprecation notice: This library is no longer actively maintained. Try the natural classifier. It doesn't have a Redis backend, but otherwise works even better.

classifier

classifier is a JavaScript naive Bayesian classifier with backends for Redis and localStorage:

var bayes = new classifier.Bayesian();

bayes.train("cheap replica watches", 'spam');
bayes.train("I don't know if this works on windows", 'not');

var category = bayes.classify("free watches");   // "spam"

The first argument to train() can be a string of text or an array of words, the second argument can be any category name you want.

using in node

If you have node you can install with npm:

npm install classifier

using in the browser

Download the latest classifier.js. In the browser you can only use the localStorage and (default) memory backends.

Redis backend

You can store the classifier state in Redis for persisting and training from multiple sources:

var bayes = new classifier.Bayesian({
  backend: {
    type: 'Redis',
    options: {
      hostname: 'localhost', // default
      port: 6379,            // default
      name: 'emailspam'      // namespace for persisting
    }
  }
});

bayes.train("cheap replica watches", 'spam', function() {
  console.log("trained");
});

bayes.classify("free watches", function(category) {
  console.log("classified in: " + category);
});

JSON

You can serialize and load in the classifier's state with JSON:

var json = bayes.toJSON();

bayes.fromJSON(json);

Other options

Bayesian() takes an options hash that you can define these properties in:

backend

The backend property takes a type which is one of 'Redis', 'localStorage', or 'memory'(default). The backend also has an options hash. The Redis backend takes hostname, port, password, name, db, and error (an error callback) in its options. The localStorage backend takes name for namespacing.

thresholds

Specify the classification thresholds for each category. To classify an item in a category with a threshold of x the probably that item is in the category has to be more than x times the probability that it's in any other category. Default value is 1. A common threshold setting for spam is:

thresholds: {
  spam: 3,
  not: 1
}

default

The default category to throw an item in if it can't be classified in any of the categories. The default value of default is "unclassified".

classifier-2's People

Contributors

harthur avatar mrorz avatar stesie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.