Linear Regression and the Normal Equation
Linear Regression models a continuous target as a linear combination of input features :
where is the model parameter vector (including the intercept or bias ), and is the observation vector containing the features (with ).
Simple vs. Multiple Linear Regression
- Simple Linear Regression: Models the relationship between a single feature and the target . The equation simplifies to finding the best line with a specific slope () and intercept ():
- Multiple Linear Regression: Extends the concept to multiple features, where each feature gets its own weight (slope) in a multidimensional space.
Polynomial Regression
If the data is more complex than a simple straight line, we can still use linear models to fit nonlinear data. By adding powers of each feature as new features, we can train a linear model on this extended set of features. This is called Polynomial Regression. Despite fitting a curve to the data, it is still considered a linear model because the prediction is still a linear combination of the (now polynomial) features.
Parameter Estimation: Ordinary Least Squares
To train the model, we find parameters that minimize the Mean Squared Error (MSE) over the dataset:
The Closed-Form Normal Equation
To minimize the cost function, we solve analytically using the Normal Equation:
- : The design matrix of shape containing all features.
- : The target vector of shape .
Multicollinearity and SVD
If the matrix is singular (non-invertible) due to redundant, highly correlated features, standard inversion fails. Solvers compute the pseudo-inverse using Singular Value Decomposition (SVD) for stability.
Computational Complexity
Computing requires inverting an matrix. The computational complexity is between and , making the Normal Equation expensive when the number of features is large.
Example: Computing the Normal Equation
The following example demonstrates computing model coefficients using the Normal Equation:
Interactive Lab
Compute model parameters analytically using the Normal Equation. Alter the synthetic target equation coefficients to see if the equation adapts and finds the new parameters.
Exercise
Test your understanding of the analytical parameter estimation limits: