There are primarily 2 solutions to evaluating linear regression
Analytical Closed Form Solution (OLS Method)
The closed-form solution for linear regression, also known as the Normal Equation, provides a direct mathematical formula to calculate the optimal parameters without iteration. This approach uses calculus to minimize the cost function by taking its derivative, setting it to zero, and solving for the weights.
The Formula
The closed-form solution is expressed as:
Where:
- is the weight vector (parameters to find)
- is the design matrix containing input features (N samples × D features)
- is the target vector containing output values
- is the transpose of X
Derivation Steps
The derivation involves minimizing the least-squares loss function.
The Loss Function is:
or
Where:
- is the actual observed value
- is the predicted value from the model
- represents the model parameters (weights)
- is the number of data points
In vector notation, it can be written as:
Closed form solution involves taking derivative of the above:
Taking the derivative with respect to W and setting it to zero gives:
Gradient Descent Method
To use gradient descent, we first need a way to measure how “wrong” our current model is. In linear regression, we typically use the Mean Squared Error (MSE):
Where m is the slope and b is the intercept. Our goal is to find the values of m and b that minimize
To find the “steepest direction,” we calculate the partial derivatives (the gradient) of the cost function with respect to each parameter.
Partial derivative of m:
Partial derivative of b:
Once we have the gradient, we update our parameters using the Learning Rate (). The learning rate determines how big of a “step” we take.
Leave a Reply