import { perceptron } from "https://deno.land/x/simplestatistics@v7.7.6/index.js";
This is a single-layer Perceptron Classifier that takes arrays of numbers and predicts whether they should be classified as either 0 or 1 (negative or positive examples).
Examples
// Create the model
var p = new PerceptronModel();
// Train the model with input with a diagonal boundary.
for (var i = 0; i < 5; i++) {
p.train([1, 1], 1);
p.train([0, 1], 0);
p.train([1, 0], 0);
p.train([0, 0], 0);
}
p.predict([0, 0]); // 0
p.predict([0, 1]); // 0
p.predict([1, 0]); // 0
p.predict([1, 1]); // 1
// Create the model var p = new PerceptronModel(); // Train the model with input with a diagonal boundary. for (var i = 0; i < 5; i++) { p.train([1, 1], 1); p.train([0, 1], 0); p.train([1, 0], 0); p.train([0, 0], 0); } p.predict([0, 0]); // 0 p.predict([0, 1]); // 0 p.predict([1, 0]); // 0 p.predict([1, 1]); // 1