Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

js neural networks and classifiers

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

brain

brain is a limited JavaScript supervised machine learning library. Full API here. Neural network example:

var net = new brain.NeuralNetwork();
net.train([{input: [0, 0], output: [0]},
           {input: [0, 1], output: [1]},
           {input: [1, 0], output: [1]},
           {input: [1, 1], output: [0]}]);

var output = net.run([1, 0]);

The output will be [0.987] or something close like that. There's no reason to use a neural network to figure out XOR (-:, so here's a more involved, realistic example: Demo: training a neural network to recognize color contrast

Naive Bayesian classifier example:

var bayes = new brain.BayesianClassifier();

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

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

using in node

If you have node you can install with npm:

npm install brain

using in the browser

Download the latest brain.js. If you're using BayesianClassifier, you can only use the localStorage and (default) in-memory backends. If you're using the NeuralNetwork you should try to train the network offline (or on a Worker) and use the toFunction() or toJSON() options to plug the pre-trained network in to your website.

tests

Running the tests requires checking out the code and installing the dev dependencies: npm install --dev. To run the suite of tests:

node test/runtests.js

To run the other tests: browser and cross-validation tests

build

To build a browser file from the CommonJS package you'll need jake:

npm install jake -g

jake build
jake minify
Something went wrong with that request. Please try again.