Skip to content

PerceptronModel

Defined in: src/perceptron.js:21

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

// 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

new PerceptronModel(): PerceptronModel

Defined in: src/perceptron.js:24

PerceptronModel

bias: number

Defined in: src/perceptron.js:31


weights: any[]

Defined in: src/perceptron.js:27

predict(features): number

Defined in: src/perceptron.js:41

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

number[]

an array of features as numbers

number

1 if the score is over 0, otherwise 0; null if the model has not been trained on feature arrays of this length


train(features, label): PerceptronModel

Defined in: src/perceptron.js:72

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

number[]

an array of features as numbers

number

either 0 or 1

PerceptronModel

this, or null if the label is not 0 or 1