@botpress/node-svm
v0.0.6
Published
node bindings for libsvm
Downloads
21
Keywords
Readme
Node-SVM-NAPI
What
This package is a nodejs binding for Libsvm.
It's strongly inspired by node-svm, but shares no lines of code with it and has a fairly different API.
It's developed and maintained by the botpress team which is by far the best conversational AI platform there is for nodejs environment (probably the best conversational AI platform there is at all).
Why
Why did we make a complete reimplementation? What is different from previous node-svm ? There's actually two reasons:
node-svm doesn't build for nodejs version > 10...
It's written using Native Abstractions for Node.js (nan) which is an old API for node binding developpement.
Our binding is written using node-addon-api (napi) which is intended to insulate addons from changes in the underlying JavaScript engine…
node-svm is not a simple wrapper, it does add some extra logic which we don't think a node binding should be doing. Our binding is a much simpler wrapper and add no unnecessary logic to Libsvm.
Installation
To install locally in a project, simply type command
yarn add @botpress/node-svm
Usage
Here's an example of how to use
const { makeSvm } = require('@botpress/node-svm')
async function main() {
const svm = await makeSvm()
const train_params = {
svm_type: 0,
kernel_type: 2,
degree: 3,
gamma: 0.5,
coef0: 0.0,
cache_size: 100,
eps: 0.1,
C: 1.0,
nr_weight: 0,
weight_label: [0, 0],
weight: [0.0, 0.0],
nu: 0.5,
p: 0.0,
shrinking: 1,
probability: 0
}
const x = [
[0, 0],
[0, 1],
[1, 0],
[1, 1]
]
const y = [0, 1, 1, 0]
svm.train(train_params, x, y)
const model_object = svm.get_model() // this is equivalent to the svm_model object of libsvm
console.log(model_object)
svm.set_model(model_object) // for testing purposes (not mandatory)
const prediction = svm.predict([1, 1]) // outputs 0
console.log('prediction', prediction)
}
main()
.then(() => console.log('Done.'))
.catch((err) => console.log(err))
For more details about training parameters, check out cjlin1/libsvm readme file.