Introduction

wink-perceptron

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.

Installation

Use npm to install:

npm install wink-perceptron --save

Documentation

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

perceptron

Creates an instance of wink-perceptron.

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

API Methods

defineConfig

Defines the hyperparameters for perceptron.

defineConfig(config: object): object
Parameters
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.
Returns
object: a copy of configuration defined.
Example
// Enable random shuffling of examples!
myPerceptron.defineConfig( { shuffleData: true } );
// -> { shuffleData: true, maxIterations: 9, featureExtractor: null }

learn

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

learn(examples: Array<array>): number
Parameters
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> } .
Returns
number: number of examples passed.
Example
myPerceptron.learn(  examples );

predict

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

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