1.0.4 • Published 4 years ago
percyml v1.0.4
PercyML
A simple, lightweight package for linear classification implementing the standard and averaged Perceptron algorithms.
Creating a model
const { Perceptron, AveragedPerceptron } = require('percyml');
const inputValues = [[...], [...], ...]; // input array with each item being its own n-dimensional feature array
const outputValues = [...]; // these do NOT need to be mapped to -1 and 1, that will be done internally
const options = { // the completely optional additional parameters, shown here at their defaults
learningRate: 0.01,
weights: [0, ..., 0], // initial weights, start at 0 by default
}
const model = new Perceptron(inputValues, outputValues, options);
const averagedModel = new AveragedPerceptron(inputValues, outputValues, options);
model.train(iterations);
console.log(model.predict(testValue)); //=> predicted output
averagedModel.train(iterations);
console.log(averagedModel.predict(testValue)); //=> predicted output
Notes
- Both classes are implemented to shuffle the values before each training iteration to counteract the Perceptrons' tendency to overfit later examples.
- Both classes have a method called
rawPredict
that functions exactly likepredict
, except returns the calculated value BEFORE mapping to -1 or 1 (or whatever your outputs were if you provided them). - The
train
method returns its instance, so method calls can be chained.