在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):junku901/machine_learning开源软件地址(OpenSource Url):https://github.com/junku901/machine_learning开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):machine_learningMachine learning library for node.js. You can also use this library in browser. InstallationNode.js
To use this library in browser, include machine_learning.min.js file. <script src="/js/machine_learning.min.js"></script> Here is the API Documentation. (Still in progress) Features
Implementation DetailsSVM is using Sequential Minimal Optimization (SMO) for its training algorithm. For Decision Tree, Classification And Regression Tree (CART) was used for its building algorithm. UsageLogistic Regressionvar ml = require('machine_learning');
var x = [[1,1,1,0,0,0],
[1,0,1,0,0,0],
[1,1,1,0,0,0],
[0,0,1,1,1,0],
[0,0,1,1,0,0],
[0,0,1,1,1,0]];
var y = [[1, 0],
[1, 0],
[1, 0],
[0, 1],
[0, 1],
[0, 1]];
var classifier = new ml.LogisticRegression({
'input' : x,
'label' : y,
'n_in' : 6,
'n_out' : 2
});
classifier.set('log level',1);
var training_epochs = 800, lr = 0.01;
classifier.train({
'lr' : lr,
'epochs' : training_epochs
});
x = [[1, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0],
[1, 1, 1, 1, 1, 0]];
console.log("Result : ",classifier.predict(x)); MLP (Multi-Layer Perceptron)var ml = require('machine_learning');
var x = [[0.4, 0.5, 0.5, 0., 0., 0.],
[0.5, 0.3, 0.5, 0., 0., 0.],
[0.4, 0.5, 0.5, 0., 0., 0.],
[0., 0., 0.5, 0.3, 0.5, 0.],
[0., 0., 0.5, 0.4, 0.5, 0.],
[0., 0., 0.5, 0.5, 0.5, 0.]];
var y = [[1, 0],
[1, 0],
[1, 0],
[0, 1],
[0, 1],
[0, 1]];
var mlp = new ml.MLP({
'input' : x,
'label' : y,
'n_ins' : 6,
'n_outs' : 2,
'hidden_layer_sizes' : [4,4,5]
});
mlp.set('log level',1); // 0 : nothing, 1 : info, 2 : warning.
mlp.train({
'lr' : 0.6,
'epochs' : 20000
});
a = [[0.5, 0.5, 0., 0., 0., 0.],
[0., 0., 0., 0.5, 0.5, 0.],
[0.5, 0.5, 0.5, 0.5, 0.5, 0.]];
console.log(mlp.predict(a)); SVM (Support Vector Machine)var ml = require('machine_learning');
var x = [[0.4, 0.5, 0.5, 0., 0., 0.],
[0.5, 0.3, 0.5, 0., 0., 0.01],
[0.4, 0.8, 0.5, 0., 0.1, 0.2],
[1.4, 0.5, 0.5, 0., 0., 0.],
[1.5, 0.3, 0.5, 0., 0., 0.],
[0., 0.9, 1.5, 0., 0., 0.],
[0., 0.7, 1.5, 0., 0., 0.],
[0.5, 0.1, 0.9, 0., -1.8, 0.],
[0.8, 0.8, 0.5, 0., 0., 0.],
[0., 0.9, 0.5, 0.3, 0.5, 0.2],
[0., 0., 0.5, 0.4, 0.5, 0.],
[0., 0., 0.5, 0.5, 0.5, 0.],
[0.3, 0.6, 0.7, 1.7, 1.3, -0.7],
[0., 0., 0.5, 0.3, 0.5, 0.2],
[0., 0., 0.5, 0.4, 0.5, 0.1],
[0., 0., 0.5, 0.5, 0.5, 0.01],
[0.2, 0.01, 0.5, 0., 0., 0.9],
[0., 0., 0.5, 0.3, 0.5, -2.3],
[0., 0., 0.5, 0.4, 0.5, 4],
[0., 0., 0.5, 0.5, 0.5, -2]];
var y = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1];
var svm = new ml.SVM({
x : x,
y : y
});
svm.train({
C : 1.1, // default : 1.0. C in SVM.
tol : 1e-5, // default : 1e-4. Higher tolerance --> Higher precision
max_passes : 20, // default : 20. Higher max_passes --> Higher precision
alpha_tol : 1e-5, // default : 1e-5. Higher alpha_tolerance --> Higher precision
kernel : { type: "polynomial", c: 1, d: 5}
// default : {type : "gaussian", sigma : 1.0}
// {type : "gaussian", sigma : 0.5}
// {type : "linear"} // x*y
// {type : "polynomial", c : 1, d : 8} // (x*y + c)^d
// Or you can use your own kernel.
// kernel : function(vecx,vecy) { return dot(vecx,vecy);}
});
console.log("Predict : ",svm.predict([1.3, 1.7, 0.5, 0.5, 1.5, 0.4])); KNN (K-nearest neighbors)var ml = require('machine_learning');
var data = [[1,0,1,0,1,1,1,0,0,0,0,0,1,0],
[1,1,1,1,1,1,1,0,0,0,0,0,1,0],
[1,1,1,0,1,1,1,0,1,0,0,0,1,0],
[1,0,1,1,1,1,1,1,0,0,0,0,1,0],
[1,1,1,1,1,1,1,0,0,0,0,0,1,1],
[0,0,1,0,0,1,0,0,1,0,1,1,1,0],
[0,0,0,0,0,0,1,1,1,0,1,1,1,0],
[0,0,0,0,0,1,1,1,0,1,0,1,1,0],
[0,0,1,0,1,0,1,1,1,1,0,1,1,1],
[0,0,0,0,0,0,1,1,1,1,1,1,1,1],
[1,0,1,0,0,1,1,1,1,1,0,0,1,0]
];
var result = [23,12,23,23,45,70,123,73,146,158,64];
var knn = new ml.KNN({
data : data,
result : result
});
var y = knn.predict({
x : [0,0,0,0,0,0,0,1,1,1,1,1,1,1],
k : 3,
weightf : {type : 'gaussian', sigma : 10.0},
// default : {type : 'gaussian', sigma : 10.0}
// {type : 'none'}. weight == 1
// Or you can use your own weight f
// weightf : function(distance) {return 1./distance}
distance : {type : 'euclidean'}
// default : {type : 'euclidean'}
// {type : 'pearson'}
// Or you can use your own distance function
// distance : function(vecx, vecy) {return Math.abs(dot(vecx,vecy));}
});
console.log(y); K-means clusteringvar ml = require('machine_learning');
var data = [[1,0,1,0,1,1,1,0,0,0,0,0,1,0],
[1,1,1,1,1,1,1,0,0,0,0,0,1,0],
[1,1,1,0,1,1,1,0,1,0,0,0,1,0],
[1,0,1,1,1,1,1,1,0,0,0,0,1,0],
[1,1,1,1,1,1,1,0,0,0,0,0,1,1],
[0,0,1,0,0,1,0,0,1,0,1,1,1,0],
[0,0,0,0,0,0,1,1,1,0,1,1,1,0],
[0,0,0,0,0,1,1,1,0,1,0,1,1,0]< |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论