Creating and experimenting with linear models
A small linear model maps feature vectors to predictions with matrix multiplication. A controlled experiment compares predictions with observations while keeping the data split and evaluation measure explicit.
What you will learn
- Compute a model prediction
- Calculate residuals and an error metric
- Design a comparable held-out experiment
Work through one complete example
- Suppose a model predicts three outputs by y=Wx, where W=[[1,1,0],[2,0,1],[0,1,1]].
- For feature vector x=(2,1,3), the prediction is y=(3,7,4).
- For target t=(3,5,4), the residual t−y=(0,−2,0); report its squared error 4 before changing the model.
- Change one modeling choice at a time, evaluate on held-out data, and compare the same metric. A lower training error alone does not show better generalization.
Objective 1: Compute a model prediction
- Compute Wx for x=(2,1,3) in the main example.
- The row products give (3,7,4).
Objective 2: Calculate residuals and an error metric
- Find squared error for target (3,5,4).
- Residual (0,−2,0) gives squared error 4.
Objective 3: Design a comparable held-out experiment
- Can training error 4 for one model be compared with test error 3 for another?
- No. Use the same held-out set and metric and record the changed modeling choice.
A common mistake
State the assumptions before using the formula.
Review first
Continue learning
Creating and experimenting with linear models
Interactive diagnosis and practice load in the learning app. You can read these lesson notes without JavaScript.