Skip to content

Instantly share code, notes, and snippets.

@wasdee
Last active April 20, 2020 20:35
Show Gist options
  • Save wasdee/87a6dc0b8884affb2a546ca6036cad04 to your computer and use it in GitHub Desktop.
Save wasdee/87a6dc0b8884affb2a546ca6036cad04 to your computer and use it in GitHub Desktop.
[Reproducibility In Data Science] #Python
# cite: https://www.youtube.com/watch?v=Ys8ofBeR2kA
# Run python or jupyter with
# $ PYTHONHASHSEED=0 jupyter notebook
# $ PYTHONHASHSEED=0 python code.py
# check
if os.environ.get("PYTHONHASHSEED") != "0":
raise Exception("You must set PYTHONHASHSEED=0 when starting the Jupyter server to get reproducible results.")
import random
random.seed(42)
import numpy as np
np.random.seed(42)
import tensorflow as tf
tf.set_random_seed(42)
# check for other library as well
@ceciliassis
Copy link

Awesome! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment