Skip to main content
Module

x/simplestatistics/index.js>perceptron

simple statistics for node & browser javascript
Go to Latest
class perceptron
import { perceptron } from "https://deno.land/x/simplestatistics@v7.7.5/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

Constructors

new
perceptron()

Methods

predict(features)

Predict: Use an array of features with the weight array and bias to predict whether an example is labeled 0 or 1.

train(features, label)

Train the classifier with a new example, which is a numeric array of features and a 0 or 1 label.