clustering icon indicating copy to clipboard operation
clustering copied to clipboard

Can I i have an identification item that can be ignored by clusterfck.kmeans

Open valentinvieriu opened this issue 11 years ago • 5 comments

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

valentinvieriu avatar Jun 17 '13 10:06 valentinvieriu

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);

benjeffery avatar Jun 20 '13 16:06 benjeffery

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.

harthur avatar Jul 08 '13 17:07 harthur

Have you made any performance tests using a Float64Array? This could be very interesting.

irony avatar May 13 '14 05:05 irony

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.

Innarticles avatar Sep 21 '15 12:09 Innarticles

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.

benjeffery avatar Sep 21 '15 14:09 benjeffery