Exercises
These exercises ask you to assemble the habits from the Python subject into one small experiment.
What is the workflow order used in this chapter?
Select one choice, then check.
Hint
The workflow starts with configuration and ends with a saved or printed summary.
Solution
The workflow order is:
configuration -> data -> computation -> plot -> summary
That order makes the experiment easier to rerun and inspect.
Edit the code so it prints shapes: (4,) (4,).
Create paired arrays
Ready to run.
Hint
Use:
y = 2.0 * x + noise
Solution
One fix is:
The arrays match because noise was created with the same size as x.
Which expression computes mean squared error?
Answer it first, then check.
Hint
Mean squared error has three steps: subtract, square, average.
Solution
Use:
((prediction - y) ** 2).mean()
This computes squared errors and then averages them.
Edit the code so it prints best: 2.0.
Choose the lowest-loss slope
Ready to run.
Hint
Inside the loop, compare loss with best_loss. If it is smaller, update both
best_slope and best_loss.
Solution
One fix is:
The slope 2.0 gives zero loss for this exact data.
Name one field that should be saved in the summary so the experiment can be rerun.
Answer it first, then check.
Hint
The seed is the most direct answer because it controls the noisy data.
Solution
The most direct answer is:
seed
The summary should also record configuration values and results, but the seed is essential for recreating the same noisy data.