Course materials · Machine Learning Lab

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.

Practice

Preview practice notebookDownload practice notebook

1. Sensor calibration with bias

Starting conditions

The provided code generates synthetic data by adding small noise to y=1.8x+.7 at x∈{0,.5}x\in\{0,.5\},...,3.5. Use seed=7.

Procedure

  1. Run the provided 200-epoch baseline example and plot the loss curve and prediction line.
  2. Record the learned w and b separately from the data generation coefficients in a table.
  3. Given the noise, explain whether the learned coefficients should exactly match the data generation coefficients.

Results to retain

Items to record and points to check
Model
w
b
Training MSE
Prediction for x=0x=0

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

  1. Fix the initial seed and data for all runs.
  2. Record the final MSE and the loss at epochs 1, 20, and 200.
  3. Distinguish the smallest final loss from the fastest initial decrease.

Results to retain

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

  1. Plot the two prediction lines in the same figure.
  2. Record the predictions at x∈{0,.25,1.25,2.75}x\in\{0,.25,1.25,2.75\} in a table.
  3. Explain the difference between increasing training iterations and allowing bias in the model.

Results to retain

Items to record and points to check
Use bias
Training MSE
x=0x=0
x=.25x=.25
x=1.25x=1.25
x=2.75x=2.75

Points to check

  • Did you avoid mistaking the generated data for a problem without bias?
  • Did you distinguish model assumptions from optimization conditions?