machine_learning
Machine learning library for node.js. You can also use this library in browser.
Installation
Node.js
$ npm install machine_learning
To use this library in browser, include machine_learning.min.js file.
Here is the API Documentation. (Still in progress)
Features
- Logistic Regression
- MLP (Multi-Layer Perceptron)
- SVM (Support Vector Machine)
- KNN (K-nearest neighbors)
- K-means clustering
- 3 Optimization Algorithms (Hill-Climbing, Simulated Annealing, Genetic Algorithm)
- Decision Tree
- NMF (non-negative matrix factorization)
Implementation Details
SVM is using Sequential Minimal Optimization (SMO) for its training algorithm.
For Decision Tree, Classification And Regression Tree (CART) was used for its building algorithm.
Usage
Logistic Regression
var ml = ;var x = 111000 101000 111000 001110 001100 001110;var y = 1 0 1 0 1 0 0 1 0 1 0 1; var classifier = 'input' : x 'label' : y 'n_in' : 6 'n_out' : 2; classifier; var training_epochs = 800 lr = 001; classifier; x = 1 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 0; console;
MLP (Multi-Layer Perceptron)
var ml = ;var x = 04 05 05 0 0 0 05 03 05 0 0 0 04 05 05 0 0 0 0 0 05 03 05 0 0 0 05 04 05 0 0 0 05 05 05 0;var y = 1 0 1 0 1 0 0 1 0 1 0 1; var mlp = 'input' : x 'label' : y 'n_ins' : 6 'n_outs' : 2 'hidden_layer_sizes' : 445; mlp; // 0 : nothing, 1 : info, 2 : warning. mlp; a = 05 05 0 0 0 0 0 0 0 05 05 0 05 05 05 05 05 0; console;
SVM (Support Vector Machine)
var ml = ;var x = 04 05 05 0 0 0 05 03 05 0 0 001 04 08 05 0 01 02 14 05 05 0 0 0 15 03 05 0 0 0 0 09 15 0 0 0 0 07 15 0 0 0 05 01 09 0 -18 0 08 08 05 0 0 0 0 09 05 03 05 02 0 0 05 04 05 0 0 0 05 05 05 0 03 06 07 17 13 -07 0 0 05 03 05 02 0 0 05 04 05 01 0 0 05 05 05 001 02 001 05 0 0 09 0 0 05 03 05 -23 0 0 05 04 05 4 0 0 05 05 05 -2; var y = -1-1-1-1-1-1-1-1-1-11111111111; var svm = x : x y : y; svm; console;
KNN (K-nearest neighbors)
var ml = ; var data = 10101110000010 11111110000010 11101110100010 10111111000010 11111110000011 00100100101110 00000011101110 00000111010110 00101011110111 00000011111111 10100111110010 ; var result = 2312232345701237314615864; var knn = data : data result : result; var y = knn; console;
K-means clustering
var ml = ; var data = 10101110000010 11111110000010 11101110100010 10111111000010 11111110000011 00100100101110 00000011101110 00000111010110 00101011110111 00000011111111 10100111110010 ; var result = mlkmeans; console;console;
Hill-Climbing
var ml = ; var { var cost = 0; forvar i =0; i<14;i++ // 15-dimensional vector cost += 05*i*veci*Math/veci+1 cost += 3*vec14/vec0; return cost;}; var domain = ;forvar i=0;i<15;i++ domain; // domain[idx][0] : minimum of vec[idx], domain[idx][1] : maximum of vec[idx]. var vec = mloptimize; console;console;
Simulated Annealing
var ml = ; var { var cost = 0; forvar i =0; i<14;i++ // 15-dimensional vector cost += 05*i*veci*Math/veci+1 cost += 3*vec14/vec0; return cost;}; var domain = ;forvar i=0;i<15;i++ domain; // domain[idx][0] : minimum of vec[idx], domain[idx][1] : maximum of vec[idx]. var vec = mloptimize; console;console;
Genetic Algorithm
var ml = ; var { var cost = 0; forvar i =0; i<14;i++ // 15-dimensional vector cost += 05*i*veci*Math/veci+1 cost += 3*vec14/vec0; return cost;}; var domain = ;forvar i=0;i<15;i++ domain; // domain[idx][0] : minimum of vec[idx], domain[idx][1] : maximum of vec[idx]. var vec = mloptimize; console;console;
Decision Tree
// Reference : 'Programming Collective Intellignece' by Toby Segaran. var ml = ; var data ='slashdot''USA''yes'18 'google''France''yes'23 'digg''USA''yes'24 'kiwitobes''France''yes'23 'google''UK''no'21 '(direct)''New Zealand''no'12 '(direct)''UK''no'21 'google''USA''no'24 'slashdot''France''yes'19 'digg''USA''no'18 'google''UK''no'18 'kiwitobes''UK''no'19 'digg''New Zealand''yes'12 'slashdot''UK''no'21 'google''UK''yes'18 'kiwitobes''France''yes'19;var result = 'None''Premium''Basic''Basic''Premium''None''Basic''Premium''None''None''None''None''Basic''None''Basic''Basic'; var dt = data : data result : result; dt; // dt.print(); console; dt; // 1.0 : mingain.dt;
NMF (Non-negative matrix factorization)
var ml = ;var matrix = 2228 4964; var result = mlnmf; console;console;
License
(The MIT License)
Copyright (c) 2014 Joon-Ku Kang <junku901@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.