implicit icon indicating copy to clipboard operation
implicit copied to clipboard

Getting different output from same code each time

Open narenakurati opened this issue 6 years ago • 2 comments

Used this article to help use the implicit package.

However, every time I run my code, I get a different set of recommendations. It seems like there might be an issue with the seed, so I tried setting random.seed(1), but the problem still persists. What can I do to make sure I get the same result each time?

alpha_val = 15 model = implicit.als.AlternatingLeastSquares(factors=20, regularization=0.1, iterations=20) data_conf = (sparse_item_account * alpha_val).astype('double') model.fit(data_conf)

narenakurati avatar Sep 18 '19 18:09 narenakurati

Implicit uses at least two kinds of random number generator.

  1. C++ random number generator (BPR, LMF Only)
  2. Numpy random number generator

Numpy rng can be fixed using np.random.seed(), but I don't know how to fix c++ random number generator...

ita9naiwa avatar Oct 02 '19 01:10 ita9naiwa

If you really need the seed to be fixed, try setting the number of threads to one. I am not positive how this ALS implementation works internally, but BPR uses the numpy random to seed c++ random generators -one per thread. This makes the generated number sequence fixed, which makes the results fixed as long as the same number is used for the same part of the matrix, which can be only guaranteed if there is a single thread - otherwise, the execution order is unknown and results can still vary.

chedatomasz avatar Nov 14 '19 12:11 chedatomasz