1

I am using the set.seed and kmeans function. Although I use set.seed my cluster centers keep changing but my data isn't. And, it only changes from day to day, not daily. So, within the same day there aren't any changes, but the next day my clusters will change. I'm assuming the set.seed function is causing this. If so, does anyone know how to set randomness within kmeans or similar function? Can someone give me some insight. Sample code below:

set.seed(1234)

ITsegment2 <- kmeans(iTeller_z, 4)
user3067851
  • 524
  • 1
  • 6
  • 20
  • 4
    A reproducible example would sure help… – AkselA Jun 15 '17 at 14:27
  • https://stackoverflow.com/questions/21712157/r-bizarre-behavior-of-set-seed?rq=1 – amonk Jun 15 '17 at 14:35
  • @AkselA as the clusters change from day to day, I cannot make it happen in a session. I just noticed that without changing the data cluster center values are changing and they shouldn't if the seed hasn't changed. It is more of a concept question. – user3067851 Jun 15 '17 at 14:47
  • "Concept" questions are (by and large) considered off topic as being too broad, vague and opinion based. For such a question to have value its case needs to be made very clear. You have not made your case clear at all, as such your question is of little value and is in danger of getting flagged for closure. You've been here for more than three years and have asked 20-odd questions, surely you've figured out how this place works by now? – AkselA Jun 15 '17 at 18:10
  • @AkselA why does set.seed result in different results when used from one day to the next is too broad? really? If you don't know why or this question is too broad then please skip it. – user3067851 Jun 15 '17 at 19:23
  • No, but that doesn't seem to be the question you're asking. If you wondered wether `set.seed` is the cause for this behaviour naturally you would have tested for this. I see no evidence of such tests (such as reproducible code). You're the one calling it a "concept" question as an excuse for the lack of specifics, but as a concept question it is also falling far short on information that will let us give you a good answer. – AkselA Jun 15 '17 at 19:36
  • @AkselA Since I can only 'reproduce' the problem by waiting until the next day I will have to wait until tomorrow to do so. I will set a seed today save results and then do same tomorrow. – user3067851 Jun 15 '17 at 19:47
  • That sounds like a good start. Have you tried something very simple, like `set.seed(1); runif(1)` yet? For the record, on my end that returns `0.2655087`. – AkselA Jun 15 '17 at 19:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/146789/discussion-between-user3067851-and-aksela). – user3067851 Jun 15 '17 at 19:55

1 Answers1

0

There is probably something more clever but here an easy solution :

set.seed(as.numeric(Sys.Date()))

Sys.Date() returns the today date, as.numeric transform's it into a number...So the number will change every day .

Cheers

Nico Coallier
  • 676
  • 1
  • 8
  • 22