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

nodeml

v0.4.0

Published

node.js machine learning package

Downloads

1,427

Readme

nodeml

Machine Learning Framework for Node

Summary

Installation

installation on your project

npm install --save nodeml

use example

const {Bayes} = require('nodeml');
let bayes = new Bayes();

bayes.train({'fun': 3, 'couple': 1}, 'comedy');
bayes.train({'couple': 1, 'fast': 1, 'fun': 3}, 'comedy');
bayes.train({'fast': 3, 'furious': 2, 'shoot': 2}, 'action');
bayes.train({'furious': 2, 'shoot': 4, 'fun': 1}, 'action');
bayes.train({'fly': 2, 'fast': 3, 'shoot': 2, 'love': 1}, 'action');

let result = bayes.test({'fun': 3, 'fast': 3, 'shoot': 2});
console.log(result); // this print {answer: , score: }

Document

nodeml.sample

Sample dataset for test

const {sample} = require('nodeml');

// bbc: Function() => { dataset: [ {} , ... ], labels: [ ... ] }
// bbc news dataset, sparse matrix
const bbc = sample.bbc();

// yeast: Function() => { dataset: [ [] , ... ], labels: [ ... ] }
// yeast dataset, array data
const yeast = sample.yeast();

// iris: Function() => { dataset: [ [] , ... ], labels: [ ... ] }
// iris dataset, array data
const iris = sample.iris();

// movie: Function() => [{ movie_id: '1', user_id: '97', rating: '5', like: '17' }, ...]
// movie dataset, array data
const movie = sample.movie();

nodeml.Bayes

Naive Bayes classifier

const {Bayes} = require('nodeml');
let bayes = new Bayes(); // this is bayes classfier

train: Function(data, label) => model

training bayes classifier

bayes.train([0.2, 0.5, 0.7, 0.4], 1);       
bayes.train({ 'my': 20, 'home': 30 }, 1);   

// training bulk
bayes.train([[2, 5,], [2, 1,]], [1, 2]);    
bayes.train([{}, {}], [1, 2]);              

test: Function(data) => { answer: string, score: {} }

classify document

let result = bayes.test([2, 5, 1, 4]);
let result = bayes.test({'fun': 3, 'fast': 3, 'shoot': 2});

getModel: Function () => model

get trained result

let model = bayes.getModel();
let str = JSON.stringify(model);

setModel: Function (model)

set pre-trained

bayes.setModel(JSON.parse(str));

nodeml.kNN

k-Nearest Neighbor Classifier

const {kNN} = require('nodeml');
let knn = new kNN();

train: Function(dataset, labels) => model

training

knn.train([0.2, 0.5, 0.7, 0.4], 1);       
knn.train({ 'my': 20, 'home': 30 }, 1);   

// training bulk
knn.train([[2, 5,], [2, 1,]], [1, 2]);    
knn.train([{ 'my': 20, 'home': 30 }, { 'my': 5, 'home': 10 }], [1, 2]);              

test: Function(dataset, k) => [ class1, class2, class1 ]

classify document (default k is 3)

let result = knn.test([2, 5, 1, 4]);
let result = knn.test({'fun': 3, 'fast': 3, 'shoot': 2}, 5);

getModel: Function () => model

get trained result

let model = knn.getModel();
let str = JSON.stringify(model);

setModel: Function (model)

set pre-trained

knn.setModel(JSON.parse(str));

nodeml.CNN

Convolutional Neural Network, based convnetjs

const {CNN} = require('nodeml');
let cnn = new CNN();

configure: Function (options)

options object refer trainer option at convnetjs

cnn.configure({learning_rate: 0.1, momentum: 0.001, batch_size: 5, l2_decay: 0.0001});

setModel: Function (layer or model)

layer refer at convnetjs

var layer = [];
layer.push({type: 'input', out_sx: 1, out_sy: 1, out_depth: 8});
layer.push({type: 'svm', num_classes: 10});

cnn.makeLayer(layer);

// set pre-trained
cnn.setModel(JSON.parse(str));

train: Function (data, label)

cnn.train([0.2, 0.5, 0.7, 0.4], 1);       
cnn.train({ 'my': 20, 'home': 30 }, 1);   

// training bulk
cnn.train([[2, 5,], [2, 1,]], [1, 2]);    
cnn.train([{}, {}], [1, 2]);   

test: Function(data) => { answer: string, score: {} }

classify document

let result = cnn.test([2, 5, 1, 4]);
let result = cnn.test({'fun': 3, 'fast': 3, 'shoot': 2});

getModel: Function () => model

get trained result

let model = cnn.getModel();
let str = JSON.stringify(model);

nodeml.kMeans

k-Means Clustering

const {kMeans} = require('nodeml');
let kmeans = new kMeans();

train: Function(dataset, options) => model

training

kmeans.train([[2, 5,], [2, 1,]], {
    k: 10, dm: 0.00001, iter: 100,  
    proc: (iter, j, d)=> { console.log(iter, j, d); }
});

| options | description | type | default | |---|---|---|---| | init | cluster initialize function: random, fuzzy (preparing) | string | 'random' | | k | number of cluster | integer | 3 | | dm | distortion measure | float | 0.00 | | iter | maximum iteration | integer | unlimited | | labels | supervised learning, if labels exists, detect k automatically | array | null | | proc | process handler | function | null |

test: Function(dataset) => [ class1, class2, class1 ]

classify document (default k is 3)

let result = kmeans.test([[2, 5,], [2, 1,]]);

getModel: Function () => model

get trained result

let model = kmeans.getModel();
let str = JSON.stringify(model);

setModel: Function (model)

set pre-trained

kmeans.setModel(JSON.parse(str));

nodeml.CF

Collaborative Filtering Function

const {CF, evaluation} = require('../index');

let train = [[1, 1, 2], [1, 2, 2], [1, 4, 5], [2, 3, 2],
    [2, 5, 1], [3, 1, 2], [3, 2, 3], [3, 3, 3]];
let test = [[3, 4, 1]];

const cf = new CF();
cf.train(train);
let gt = cf.gt(test);
let result = cf.recommendGT(gt, 1);

let ndcg = evaluation.ndcg(gt, result);

console.log(gt);
console.log(result);
console.log(ndcg);

train: Function


nodeml.evaluate

accuracy: Function (gt, result) => {precision, recall, f-measure, accuracy}

let {evaluate} = require('nodeml');

let original = [1, 2, 1, 1, 3]; // original label
let result = [1, 1, 2, 1, 3]; // train result label

// exec evaluate, this contains accuracy, micro/macro precision/recall/f-measure
let accuracy = evaluate.accuracy(original, result);

ndcg: Function (gt, result) => 0 ~ 1 ndcg value

let {CF, evaluate} = require('nodeml');
const cf = new CF();
let gt = cf.gt(test, 'user_id', 'movie_id', 'rating');

let result = cf.recommandToUsers(users, 40);

let ndcg = evaluation.ndcg(gt, result);