Syllabus Map
- Study map: Syllabus Study Map
Overview
-
Linear Regression is one of the simplest and most fundamental algorithms in Machine Learning for regression.
-
It models the relationship between an input variable and an output variable by fitting a straight line that best represents the data.
Mathematical Formulation
- The linear model predicts the target value as:
- Where:
- : weight (slope)
- : bias (intercept)
- : predicted value for input
Cost Function
- To measure how well our model fits the data, we use the Mean Squared Error (MSE) cost function:
- Substituting the prediction term:
Gradient Descent Optimisation
- We update parameters and iteratively to minimise the cost function:
- where is the learning rate.
Derivation of Gradients
-
Derivative of cost prediction:
-
Derivative of prediction parameters:
-
Applying chain rule:
- Gradient :
- Gradient :
Final Update Rules
Weight update:
Bias update:
Linear Regression In Practice
When to Use Linear Regression
- When relationships are approximately linear and additive.
- When you need fast training and a strong baseline.
- When coefficient interpretability matters for decisions.
- When data is large and noise is moderate.
When Not to Use Linear Regression
- When relationships are highly nonlinear without feature engineering.
- When outliers dominate the fit and robust methods are needed.
- When multicollinearity makes coefficients unstable without regularisation.
- When the target is bounded, categorical, or count-based.
Practical Notes
Preprocessing and Diagnostics
- Standardise features before applying regularisation.
- Inspect residuals for heteroscedasticity and bias.
Regularization and Features
- Use Ridge or LASSO when there are many correlated features.
- Add interaction terms only when they are justified by domain knowledge.