• This repository has been archived on 26/Sep/2023
  • Stars
    star
    625
  • Rank 71,862 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bayesian classifier with Redis backend

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".

More Repositories

1

brain

Simple feed-forward neural network in JavaScript
JavaScript
8,006
star
2

kittydar

Face detection for cats in JavaScript - demo for TXJS 2012 talk
JavaScript
1,419
star
3

replace

Command line search and replace utility
JavaScript
748
star
4

clustering

K-means and hierarchical clustering
JavaScript
498
star
5

nomnom

Option parser for node with generated usage and commands
JavaScript
470
star
6

hog-descriptor

[UNMAINTAINED] Histogram of Oriented Gradients (HOG) descriptor extractor
JavaScript
169
star
7

glossary

[UNMAINTAINED] Extract terms and keywords from a piece of text
JavaScript
168
star
8

fxconsole

[UNMAINTAINED] Remote JavaScript console for Firefox
JavaScript
127
star
9

firefox-client

[UNMAINTAINED] Node.js remote debugging client for Firefox
JavaScript
100
star
10

costco

UI for bulk editing CouchDB docs
JavaScript
56
star
11

js-select

[UNMAINTAINED] Traverse and modify objects using JSONSelect selectors
JavaScript
56
star
12

rainbow

Color tools for Firefox
JavaScript
39
star
13

txjs-slides

dzslides deck for my txjs talk
CSS
14
star
14

mac-sounds

Play default OS X sounds from node
JavaScript
9
star
15

bzhome

Bugzilla dashboard
JavaScript
8
star
16

passion-project-slides

Slides for my Passion Projects talk on Machine Learning and JS
JavaScript
7
star
17

tcm

Mozilla's new testcase manager
JavaScript
5
star
18

detect-indent

CSS
5
star
19

searchbugs

Search for Bugzilla bugs by component
JavaScript
4
star
20

test-pages

Testcase websites for devtools
JavaScript
3
star
21

devtools-guide

3
star
22

showsearch

Jetpack that shows search terms in Firefox's awesomebar
JavaScript
3
star
23

firefontfamily

A Firebug extension that highlights the rendered font-family
JavaScript
2
star
24

contextfont

Firefox addon to find fonts on websites
JavaScript
2
star
25

celestial-snips-app

Snips voice assistant that answers celestial questions
Python
2
star
26

mini-devtools

mini in-content devtools
JavaScript
2
star
27

artfulimage

The Artful Image fine printing
2
star
28

bztweaks

mirror of Bugzilla Tweaks Firefox addon (https://bitbucket.org/ehsan/bugzilla-tweaks)
JavaScript
2
star
29

fluent-talk

JavaScript
1
star
30

bugidhelper

Bugzilla bug id linkifier and tooltipifier extension
JavaScript
1
star
31

brooklynjs-slides

Write your own in-content devtools with web APIs
CSS
1
star
32

test-snips-calc

Test Snips Calc Action
Python
1
star
33

harth

harth's no.de code
1
star
34

wwcode

A small website for Women Who Code SF
JavaScript
1
star
35

celestial-jupyter

Jupyter Notebook
1
star
36

test.js

Whatever's in my ~/test.js
JavaScript
1
star