npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@botpress/node-svm

v0.0.6

Published

node bindings for libsvm

Downloads

67

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:

  1. 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…

  2. 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.