31 lines
941 B
JavaScript
31 lines
941 B
JavaScript
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 model = ml.learn({
|
|
algorithm: ml.ML.KMN,
|
|
data : data,
|
|
k : 4,
|
|
epochs: 100,
|
|
|
|
distance : {type : "pearson"}
|
|
// default : {type : 'euclidean'}
|
|
// {type : 'pearson'}
|
|
// Or you can use your own distance function
|
|
// distance : function(vecx, vecy) {return Math.abs(dot(vecx,vecy));}
|
|
});
|
|
print(toJSON(model).length+' Bytes')
|
|
|
|
print("clusters : ", model.clusters);
|
|
print("means : ", model.means);
|
|
print(ml.classify(model))
|