PercyML
A simple, lightweight package for linear classification implementing the standard and averaged Perceptron algorithms.
Creating a model
const Perceptron AveragedPerceptron = ; const inputValues = ... ... ...; // input array with each item being its own n-dimensional feature arrayconst 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: 001 weights: 0 ... 0 // initial weights, start at 0 by default const model = inputValues outputValues options;const averagedModel = inputValues outputValues options; model;console; //=> predicted output averagedModel;console; //=> 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.