Hi. Can someone explain random.seed in numpy please and any possible applications of it?
Also the link in the mission is broken: https://app.dataquest.io/m/377/estimating-probabilities/4/repeating-an-experiment
from numpy.random import seed, randint
if randint(0, 2) == 1:
I do not understand what seed is doing here.
In that screen there is a link to a previous mission that explains the
random_state argument present in many methods. NumPy also offers this functionality and one of the ways that it does that is
I won’t explain it here because it is explained in the content. If there’s somehting in the content that you find confusing, do ask about it.
It serves to reproduce results. I suspect that the real reason behind us using it here (other that reproducing results) is that we use it for answer checking. If we allowed you to not use a specific seed, the results could vary making it very hard to validate the answer.
There are other good reasons, though. One of the tenets of the scientific method is reproducibility:
- Define a question
- Gather information and resources (observe)
- Form an explanatory hypothesis
- Test the hypothesis by performing an experiment and collecting data in a reproducible manner
- Analyze the data
- Interpret the data and draw conclusions that serve as a starting point for new hypothesis
- Publish results
- Retest (frequently done by other scientists)
The example in this screen is fairly simple. Suppose, however, that it is a complicated experiment where are at some point you randomly select some data points in the middle of the experiment.
Suppose further that they lead to some unexpected results much later in the experiment. Being able to identify them so that the experiment can be reproduced with them is important.
Perfect. Makes much more sense. Appreciate it Bruno.
Good explanation if anyone needs it.