js neural networks and classifiers
Switch branches/tags
Nothing to show
Pull request Compare This branch is 66 commits behind harthur:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



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, but it's a small example (-:

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.


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


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

npm install jake -g

jake build
jake minify