Can I i have an identification item that can be ignored by clusterfck.kmeans
For example the first item is an identification item ( userid ) so that I can know who went in wich cluster.
var colors = [
['a1',20, 20, 80],
['a2',22, 22, 90],
['a3',250, 255, 253],
['a4',0, 30, 70],
['a5',200, 0, 23],
['a6',100, 54, 100],
['a7',255, 13, 8]
];
clusterfck.kmeans(colors, 3);
If I run this it just hungs. Is there a way to ignore the first item, and just consider the rest?
Thanks
You don't need this as you can set arbitrary properties on a javascript array. For example:
var colors = [
[20, 20, 80],
[22, 22, 90],
[250, 255, 253],
[0, 30, 70],
[200, 0, 23],
[100, 54, 100],
[255, 13, 8]
];
colors.forEach(function(color, i) {
//Set id for tracking purposes
color.id = i;
});
clusterfck.kmeans(colors, 3);
I think @benjeffery's method would work fine all the way. A more obvious method would be ideal though, something like:
var colors = [
{ id: "blue", value: [0, 0, 255] },
{ id: "orange", value: [200, 50, 50] }
]
where value always holds the value to be clustered on, but you can store whatever you want in the object otherwise.
This would also allow you to use Float64Arrays for the value (they can't contain arbitrary stuff like reg JS arrays). That could be a big perf win.
Have you made any performance tests using a Float64Array? This could be very interesting.
HI @harthur how do I use your above construct
var colors = [
{ id: "blue", value: [0, 0, 255] },
{ id: "orange", value: [200, 50, 50] }
]
Do I still do
clusterfck.kmeans(colors, 3);
This is not working as expected this way.
The example @harthur gave was how things might work if such a mechanism was implemented. It hasn't been, so you need to something like I suggested above.