Search code examples
python-3.xtensorflowneural-networkconv-neural-networkrecurrent-neural-network

Result changes every time I run Neural Network code


I got the results by running the code provided in this link Neural Network – Predicting Values of Multiple Variables. I was able to compute losses accuracy etc. However, every time I run this code, I get a new result. Is it possible to get the same (consistent) result?


Solution

  • The code is full of random.randint() everywhere! Furthermore, the weights are most of the time randomly set aswell, and the batch_size also has an influence (although pretty minor) in the result.

    1. Y_train, X_test, X_train are generated randomly
    2. Using adam as optimizer, means you'll be performing stochastic gradient descent. With a random beginning point of the iterations in order to converge.
    3. A batch_size of 8 means you will run batches consisting of 8 randomly selected samples.

    Solution:

    1. Set a random seed in your code to have always the random values generated with np.random.seed()
    2. Doesn't generate much of an issue although minor deviations
    3. Same as 2.

    If I find a way to have consistente sampling methods for the batch_size/epoch issue I will edit my answer.