Course Name: Advanced Momentum Trading: Machine Learning Strategies, Section No: 19, Unit No: 7, Unit type: Notebook
Quantra by QuantInsti | Courses on Algorithmic and Quantitative Trading
Everytime I run this notebook, I get different "encoded_df", which affect my predict results later on.
I need a way to get same encoded_df everytime I run, or when I duplicate to new notebook, I run the new notebook and I need to get the same results.
How to do this?
Thanks
Hello Dav,
To ensure that you get the same encoded_df each time you run your notebook, you need to make sure the process is deterministic. This involves setting random seeds for libraries that involve random number generation and controlling any data processing steps that may introduce randomness.
This includes setting seeds for NumPy, TensorFlow, and any other libraries that might use random number generation.
You can include the following piece of code in the notebook to reproduce the results every time you run it:
import random
import tensorflow as tf
Set random seeds for reproducibility
np.random.seed(42)
tf.random.set_seed(42)
random.seed(42)
The number 42 is commonly used as a seed value, the specific value of the seed is arbitrary. So any integer will work. The important part is to use the same seed value consistently to ensure reproducibility.
I hope this helps!