nodeml
Machine Learning Framework for Node
Summary
- Feature Selection
nodeml.feature.tfidf
: tfidf
- Classification
nodeml.Bayes
: Bayesnodeml.kNN
: k-Nearest Neighbornodeml.CNN
: Convolutional Neural Network (CNN)
- Clustering
nodeml.kMeans
: k-Means
- Recommendation
nodeml.CF
: User based Collaborative Filtering
- Evaluation
nodeml.accuracy
: Precision, Recall, F-Measure, Accuracynodeml.ndcg
: NDCG
Installation
installation on your project
npm install --save nodeml
use example
const Bayes = ;let bayes = ; bayes;bayes;bayes;bayes;bayes; let result = bayes;console; // this print {answer: , score: }
Document
nodeml.sample
Sample dataset for test
const sample = ; // bbc: Function() => { dataset: [ {} , ... ], labels: [ ... ] }// bbc news dataset, sparse matrixconst bbc = sample; // yeast: Function() => { dataset: [ [] , ... ], labels: [ ... ] }// yeast dataset, array dataconst yeast = sample; // iris: Function() => { dataset: [ [] , ... ], labels: [ ... ] }// iris dataset, array dataconst iris = sample; // movie: Function() => [{ movie_id: '1', user_id: '97', rating: '5', like: '17' }, ...]// movie dataset, array dataconst movie = sample;
nodeml.Bayes
Naive Bayes classifier
const Bayes = ;let bayes = ; // this is bayes classfier
train: Function(data, label) => model
training bayes classifier
bayes; bayes; // training bulkbayes; bayes;
test: Function(data) => { answer: string, score: {} }
classify document
let result = bayes;let result = bayes;
getModel: Function () => model
get trained result
let model = bayes;let str = JSON;
setModel: Function (model)
set pre-trained
bayes;
nodeml.kNN
k-Nearest Neighbor Classifier
const kNN = ;let knn = ;
train: Function(dataset, labels) => model
training
knn; knn; // training bulkknn; knn;
test: Function(dataset, k) => [ class1, class2, class1 ]
classify document (default k is 3)
let result = knn;let result = knn;
getModel: Function () => model
get trained result
let model = knn;let str = JSON;
setModel: Function (model)
set pre-trained
knn;
nodeml.CNN
Convolutional Neural Network, based convnetjs
const CNN = ;let cnn = ;
configure: Function (options)
options object refer trainer option
at convnetjs
cnn;
setModel: Function (layer or model)
layer refer at convnetjs
var layer = ;layer;layer; cnn; // set pre-trainedcnn;
train: Function (data, label)
cnn; cnn; // training bulkcnn; cnn;
test: Function(data) => { answer: string, score: {} }
classify document
let result = cnn;let result = cnn;
getModel: Function () => model
get trained result
let model = cnn;let str = JSON;
nodeml.kMeans
k-Means Clustering
const kMeans = ;let kmeans = ;
train: Function(dataset, options) => model
training
kmeans;
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;
getModel: Function () => model
get trained result
let model = kmeans;let str = JSON;
setModel: Function (model)
set pre-trained
kmeans;
nodeml.CF
Collaborative Filtering Function
const CF evaluation = ; 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 = ;cf;let gt = cf;let result = cf; let ndcg = evaluation; console;console;console;
train: Function
nodeml.evaluate
accuracy: Function (gt, result) => {precision, recall, f-measure, accuracy}
let evaluate = ; let original = 1 2 1 1 3; // original labellet result = 1 1 2 1 3; // train result label // exec evaluate, this contains accuracy, micro/macro precision/recall/f-measurelet accuracy = evaluate;
ndcg: Function (gt, result) => 0 ~ 1 ndcg value
let CF evaluate = ;const cf = ;let gt = cf; let result = cf; let ndcg = evaluation;