Helia
Helia

Reputation: 228

How to set the seed in repetiton of machine learning algorithm in R?

I am aiming to run a machine learning algorithm for 100 times, but for generalization purpose, I have to set seeds. My question is what is the best way of setting seed inside the loop of iteration? At the moment, the only way that comes to my mind is:

for (i in 1:100){
set.seed(i)

The rest of the code in here
}

Any comment would be appreciated in advance.

Upvotes: 0

Views: 129

Answers (1)

Roman Luštrik
Roman Luštrik

Reputation: 70623

Either solution works, but the "outside the loop" solution will be reproducible only as a whole while if you set it "inside the loop", each iteration will be reproducible on its own.

Upvotes: 1

Related Questions