Recall & Review
beginner
What does setting a random seed in numpy do?
Setting a random seed makes sure that the random numbers generated are the same every time you run the code. This helps in getting reproducible results.
Click to reveal answer
beginner
How do you set a random seed in numpy?
You use
np.random.seed(your_number). Replace your_number with any integer to fix the sequence of random numbers.Click to reveal answer
beginner
Why is reproducibility important in data science?
Reproducibility means you or others can run the same code and get the same results. This is important for checking work, sharing findings, and debugging.
Click to reveal answer
beginner
What happens if you don't set a random seed before generating random numbers?
If you don't set a seed, numpy will generate different random numbers each time you run the code, which can make results vary and be hard to reproduce.
Click to reveal answer
beginner
Example: How to generate 5 random numbers between 0 and 1 with a fixed seed?
```python
import numpy as np
np.random.seed(42)
rands = np.random.rand(5)
print(rands)
```
This will always print the same 5 random numbers.Click to reveal answer
What function sets the random seed in numpy?
✗ Incorrect
The correct function to set the seed is
numpy.random.seed().Why should you set a random seed in your code?
✗ Incorrect
Setting a seed makes random numbers reproducible, so results stay the same each run.
What type of value do you pass to numpy.random.seed()?
✗ Incorrect
You pass an integer to
numpy.random.seed() to fix the random sequence.If you run numpy.random.rand(3) twice without setting a seed, what happens?
✗ Incorrect
Without a seed, random numbers differ each run.
Which of these is a benefit of reproducibility in data science?
✗ Incorrect
Reproducibility helps others trust and verify your results.
Explain how to set a random seed in numpy and why it is useful.
Think about how to get the same random numbers every time.
You got /4 concepts.
Describe what happens if you do not set a random seed before generating random numbers in numpy.
Consider the effect on results when running code multiple times.
You got /4 concepts.