Linear Regression
English translation
Examining how error decreases together with the resulting prediction equation helps you assess why a learning rate or bias is needed.
Before practice
01 Without bias, what types of prediction equations are possible?
Description
Only linear equations through the origin are possible. Consider what the output at input 0 means when making your judgment.
02 If loss diverges, how would you first distinguish learning rate issues from data issues?
Description
First isolate the cause of divergence by changing only the learning rate while keeping the inputs, initialization, and iteration count fixed.
1. Sensor calibration with bias
Starting conditions
The provided code generates synthetic data by adding small noise to y=1.8x+.7 at ,...,3.5. Use seed=7.
Procedure
- Run the provided 200-epoch baseline example and plot the loss curve and prediction line.
- Record the learned w and b separately from the data generation coefficients in a table.
- Given the noise, explain whether the learned coefficients should exactly match the data generation coefficients.
Results to retain
- Plots of the data, prediction line, and loss, plus a coefficient table.
Items to record and points to check
- Model
-
- w
-
- b
-
- Training MSE
-
Points to check
- Did you check that the prediction equation is wx+b?
- Did you recalculate the final loss using the final model?
2. Comparing learning rates for the same model
Starting conditions
Fix bias=True and epoch=200, and compare lr=.01,.05,.1.
Procedure
- Fix the initial seed and data for all runs.
- Record the final MSE and the loss at epochs 1, 20, and 200.
- Distinguish the smallest final loss from the fastest initial decrease.
Results to retain
- A 3-row table and 1 loss curve.
Items to record and points to check
- lr
-
- Loss@1
-
- Loss@20
-
- Final MSE
-
- w
-
- b
-
Points to check
- Did you initialize a new model for each condition?
- Are gradients reset at every iteration?
3. Error remaining without bias
Starting conditions
Using the same data, keep lr=.05 and epoch=200, and compare bias=True/False.
Procedure
- Plot the two prediction lines in the same figure.
- Record the predictions at in a table.
- Explain the difference between increasing training iterations and allowing bias in the model.
Results to retain
- Plots for the two models, a prediction table, and a brief interpretation.
Items to record and points to check
- Use bias
-
- Training MSE
-
Points to check
- Did you avoid mistaking the generated data for a problem without bias?
- Did you distinguish model assumptions from optimization conditions?