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).
Example
Section titled “Example”// Create the modelvar 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]); // 0p.predict([0, 1]); // 0p.predict([1, 0]); // 0p.predict([1, 1]); // 1Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PerceptronModel():
PerceptronModel
Defined in: src/perceptron.js:24
Returns
Section titled “Returns”PerceptronModel
Properties
Section titled “Properties”bias:
number
Defined in: src/perceptron.js:31
weights
Section titled “weights”weights:
any[]
Defined in: src/perceptron.js:27
Methods
Section titled “Methods”predict()
Section titled “predict()”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.
Parameters
Section titled “Parameters”features
Section titled “features”number[]
an array of features as numbers
Returns
Section titled “Returns”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()
Section titled “train()”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.
Parameters
Section titled “Parameters”features
Section titled “features”number[]
an array of features as numbers
number
either 0 or 1
Returns
Section titled “Returns”PerceptronModel
this, or null if the label is not 0 or 1
