ml5-library
ml5-library copied to clipboard
Implementing random seed in kmeans
Dear ml5 community,
I'm submitting a new issue. Please see the details below.
As discussed in issue #1136 with @bomanimc I would like to improve on the kmeans implementation, by adding the option to specify a random seed. This would make sure, that the output does not vary when the random seed is set.
It is implemented in the original Tensorflow, could not find the kmeans implementation in tf.js at all. @bomanimc would be cool if you could help me get started here, or anyone else who might wanna join. I have never done anything like that before.
Thanks!
Chiming in here one year later (I wrote the ml5.js implementation of kmeans):
The non-deterministic behavior of kmeans is expected. It's also expected behavior across many other ml models (basically any that rely on randomly initialized weights or, as with kmeans, starting points).
For that reason, maybe it makes sense to:
- implement a random seed function that can be shared across all model classes
- import/reuse that func in relevant model implementations
- give each model an optional parameter to use that random seed.
If you want to update just kmeans, easiest way is probably:
- Adding random seed generator to the random.js utils file and having the
randomSamplefunc employ it (with a seed parameter) - Add a new param to
DEFAULTSand update line 86 of this file to use the new function (and feed in the new seed value)