Package Exports
- ml-svm
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ml-svm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ml-svm
Support Vector Machine in Javascript
Support Vector Machine in Javascript
Installation
npm install ml-svm
Test
$ npm install
$ npm test
Methods
new SVM([options])
Creates a new SVM instance with the given parameters or the default ones.
Arguments
options
- Object with options for the algorithm
Options
C
- regularization parametertol
- numerical tolerancemax_passes
- max number of times to iterate over alphas without changingk
- the kind of kernel, it could belineal
,polynomial
orradial
par
- parameter used in the polynomial and the radial function of the kernel
Example
var SVM = require('ml-svm');
// actually this are the default values
var options = {
C: 10,
tol: 10e-2,
max_passes: 100,
par: 2,
k: 'lineal'
};
var svm = new SVM(options);
train(X, Y)
Train the SVM with the provided X
and Y
training set.
Arguments
X
- An array of training data point in the form (x1, x2)Y
- An array of training data labels in the domain {1,-1}
Example
var X = [[0, 1], [4, 6], [2,0]];
var Y = [-1,1,-1];
var mySvm = new SVM();
mySvm.train(X, Y);
getAlphas()
Returns an array containing the Lagrange multipliers.
getThreshold()
Returns the threshold of the model function.
predict([data])
Returns for each data point the predicted label based in the model.
Arguments
data
- Data point or array of data points.
Example
// creates the SVM
var mySvm = new SVM({tol: 0.01});
// train the model
var X = [[0, 1], [4, 6], [2,0]];
var Y = [-1,1,-1];
mySvm.train(X, Y);
// here you have the answer
var ans = mySvm.predict([2,6]);
export()
Exports the model to a JSON object that can be written to disk and reloaded
load(model)
Returns a new SVM instance based on the model
.
Arguments
model
- JSON object generated withsvm.export()