Multi-class averaged perceptron

Build Status Coverage Status Inline docs dependencies Status devDependencies Status

Build machine learning models for prediction with dense or sparse data using wink-perceptron. It is a part of wink — a growing family of high quality packages for Statistical Analysis, Natural Language Processing and Machine Learning in NodeJS.


Use npm to install:

npm install wink-perceptron --save


Check out the perceptron API documentation to learn more.

Need Help?

If you spot a bug and the same has not yet been reported, raise a new issue or consider fixing it and sending a pull request.

Copyright & License

wink-perceptron is copyright 2017-18 GRAYPE Systems Private Limited.

It is licensed under the under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

Creating an Instance


Creates an instance of wink-perceptron.

perceptron(): methods
methods: object conatining set of API methods for preceptron training, prediction, etc.
// Load wink perceptron.
var ner = require( 'wink-perceptron' );
// Create your instance of wink perceptron.
var myPerceptron = ner();

API Methods


Defines the hyperparameters for perceptron.

defineConfig(config: object): object
config (object) — table below details the properties of config object.

An empty config object is equivalent to setting default configuration.

Name Description
config.shuffleData boolean (default false) determines whether or not the training examples should be randomly shuffled after each iteration a.k.a epoch.
config.maxIterations number (default 9) number of passes that must be made over the examples in order to complete the learning.
config.featureExtractor function (default null) extracts feature(s) along with the corresponding class label(s) from example prior to each iteration. This is useful when raw examples need to be passed to learn() instead of features & labels. If it extracts >1 features then each of the extracted feature/label pair is processed sequentially during learning. Note shuffleData value will only control the shuffling of input examples and not of the extracted features with this function.
object: a copy of configuration defined.
// Enable random shuffling of examples!
myPerceptron.defineConfig( { shuffleData: true } );
// -> { shuffleData: true, maxIterations: 9, featureExtractor: null }


Learns from the examples. The hyperparameters, defined via defineConfig, control learning process.

learn(examples: Array<array>): number
examples (Array<array>) — each example is a 2-element array. The first element describes example's features and the second one defines its class label. Both of these are expressed in form of an object. The features object contains name/numeric-value pairs for every feature, whereas the class label contains single name/string-value pair as { label: <class> } .
number: number of examples passed.
myPerceptron.learn(  examples );


Predicts the label for the input features. If it is unable to predict then it returns a value unknown.

predict(features: object): string
features (object) — object that contains name/value pairs for every feature.
string: predicted class label for the input features .
myPerceptron.predict( features );