Classification
Regression
Clustering
Structure Learning
Linear Regression
Models a numeric target as a weighted sum of input features, minimising mean squared error via gradient descent.
Pattern Recognition and Machine Learning — Chapter 3
C.M. Bishop · Springer (free draft available from Microsoft Research) · 2006
Algorithm
Linear Regression models the target y as a linear function of the feature vector x: ŷ = w·x + b. The weights w and bias b minimise mean squared error (MSE) over the training set. This implementation uses gradient descent on the MSE loss.
Model
Loss (Mean Squared Error)
Gradient
Update
The closed-form Normal Equations solution — — is mathematically equivalent but requires a matrix inverse that is numerically unstable for ill-conditioned feature sets. Gradient descent is preferred for general use.
Theory → Code
1
Normalise features and target to [0,1] for stable convergence
2
Gradient descent — update weights by MSE gradient
3
Predict — un-normalise the output back to original scale
4
Regression metrics — R², MAE, RMSE
Theory
Complexity
Complexity
Training (GD)
— n instances, d features, e epochsNormal Eqs.
— matrix multiply + inversionQuery
— single dot productSpace
— one weight vectorNormal equations are exact but scale poorly: matrix inversion becomes prohibitive when . Gradient descent trades exactness for scalability and is preferred in practice.
Parameters
Evaluation Metrics
R² (coefficient of determination)— proportion of variance in the target explained by the model. R²=1 is a perfect fit; R²=0 means the model does no better than predicting the mean; negative R² means it's worse.
MAE (mean absolute error) — average absolute difference between predicted and actual values, in the same units as the target.
RMSE (root mean squared error) — square root of MSE; penalises large errors more than MAE, also in target units.
Notes
Only numeric attributes are used as features. The class attribute must also be numeric (regression task). If the class is nominal, use a classifier instead.
machinelearning.js.org · open source · MIT · Marin's Web Site