Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

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

Open
valentinvieriu opened this issue Jun 17, 2013 · 5 comments

Comments

@valentinvieriu
Copy link

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

@benjeffery
Copy link

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

@harthur
Copy link
Owner

harthur commented Jul 8, 2013

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.

@irony
Copy link

irony commented May 13, 2014

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

@Innarticles
Copy link

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.

@benjeffery
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants