inferrer
v0.3.0
Published
A simple and dependency-free support vector machine (SVM) library
Downloads
21
Maintainers
Readme
inferrer
A simple and dependency-free support vector machine (SVM) library
Table of Contents
Installation
npm install inferrer --save
Using inferrer
First, require the module:
const Inferrer = require("inferrer")
Or using the import
spec:
import Inferrer from "inferrer"
Basic Usage Example
Instantiate a new SVM, and train the SVM using training examples that can be classified in a binary fashion:
// The options passed to the SVM class are optional. Details below.
const XOR = new Inferrer({ kernel: "gaussian", gamma: 2 })
XOR.train([
{ input: [ 0, 0 ], classification: -1 },
{ input: [ 0, 1 ], classification: 1 },
{ input: [ 1, 0 ], classification: 1 },
{ input: [ 1, 1 ], classification: -1 }
])
It's important to note that all training/testing inputs must be lists of the same length, and every training input must have a classification thereunto pertaining.
Once the SVM is trained, classifying test inputs is accomplished thusly, using the classify
method:
XOR.classify([ 0, 1 ])
// => 1
XOR.classify([ 0, 0 ])
// => -1
The classifyList
method can be used to classify a list of test values:
XOR.classifyList([ [ 0, 0 ], [ 0, 1 ], [ 1, 0 ], [ 1, 1 ] ])
// => [ -1, 1, 1, -1 ]
The hyperplane/offset that results from the training inputs can be accessed using the following methods, respectively:
XOR.hyperplane()
XOR.offset()
Options
kernel
: The type of SVM to be used. Defaults tolinear
.linear
: Best for data that is linearly separable.gaussian
: Best for noisy or oddly formed datasets.
c
: "Strictness" of the SVM. Larger values create a stricter hyperplane. If data is noisy, it may be best to drop the value ofc
to create a hyperplane that best classifies the dataset. Defaults to3
Advanced Options
tolerance
: Tolerance of the SVM. Defaults to0.001
gamma
: This defines the "spread" of gaussian kernels. The larger thegamma
value, the tighter the hyperplane will wrap positive values. Defaults to0.1
To Do
- [x] Basic Functionality
- [x] Sequential Minimal Optimization Algorithm
- [x] Classify, Hyperplane, and Offset Methods
- [x] Defaults Values
- [x] Classification on a List of Values
- [ ] Kernel Functions
- [x] Linear Kernel
- [x] Gaussian Kernel (RBF)
- [ ] Polynomial Kernel
- [ ] Complete Test Suite
About
Basic information regarding support vector machines and this library
What is a SVM?
A support vector machine is a machine learning tool used primarily for binary classification and regression. It is a "supervised" machine learning technique, meaning the SVM requires training data to base classifications on. In many cases, a SVM is a more accurate classifier than an artificial neural network.
SMO
SMO, or sequential minimal optimization, is an algorithm for solving SVMs devised by John C. Platt. The original research paper is linked in the sources section. This library utilizes the SMO algorithm for training SVMs. The SMO algorithm was chosen because it is less memory intensive and requires less computing power than other SVM algorithms.
Sources
Sequential Minimal Optimization, John C. Platt
Support Vector Machines Succinctly, Alexandre Kowalczyk
Gaussian (Radial Basis Function) Kernel, University of Wisconsin
Contribute
I encourage opening issue tickets using the issue tracker. Please open a ticket on the issues page before submitting any pull requests to address said issue! For features and enhancements, please open a detailed, well formatted pull request outlining the necessity and benefit, as well as basic usage examples.
License
MIT © Cody Moncur