j6
Version:
Javascript scientific library (like R, NumPy, Matlab)
46 lines (40 loc) • 1.71 kB
JavaScript
var j6 = require('../../lib/j6')
var x = [[0.4, 0.5, 0.5, 0., 0., 0.],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]];
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 j6.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]));