Multiple Linear Regression › Mathematical Foundation
Machine Learning from ScratchAll chapters Multiple Linear Regression › Mathematical FoundationOne section · Sections in this chapter2 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Multiple linear regression extends the simple linear regression model to incorporate multiple predictor variables. The mathematical foundation builds upon the principles of ordinary least squares (OLS) estimation, which is covered in detail in the dedicated OLS chapter.
Model Specification
The multiple linear regression model can be written as:
where:
- : observed value of the target variable for the -th observation
- : intercept (bias term) - the predicted value of when all features equal zero
- : coefficients (slopes) for each feature, representing the partial effect of each feature
- : values of the features for the -th observation
- : error term (residual) - the difference between the actual and predicted values
The key insight is that each coefficient represents the partial effect of feature on the target variable, holding all other features constant. This is the fundamental difference from simple linear regression, where we only consider one feature at a time.
Matrix Notation
When working with observations and features, the model can be written compactly using matrix notation:
where:
- : vector containing all observed target values
- : design matrix containing all feature values with a column of ones for the intercept
- : vector of coefficients (including intercept)
- : vector of error terms (residuals)
The design matrix has the structure:
The first column of ones enables estimation of the intercept term, while subsequent columns contain the feature values for each observation.
Coefficient Estimation
The coefficients in multiple linear regression are estimated using the Ordinary Least Squares (OLS) method, which finds the values of that minimize the sum of squared differences between observed and predicted values.
The OLS solution is given by the closed-form formula:
where:
- : estimated coefficient vector (including intercept)
- : matrix of feature cross-products
- : inverse of the cross-product matrix
- : vector of feature-target covariances
For a detailed mathematical derivation of this formula, including the normal equations and computational considerations, see the dedicated OLS chapter.
Key Properties
The OLS solution has several important properties:
- Unbiased: The estimates are unbiased under standard regression assumptions
- Efficient: Among all unbiased linear estimators, OLS has the smallest variance
- Consistent: As sample size increases, the estimates converge to the true values
While the closed-form solution is mathematically elegant, computing can be problematic when:
- The matrix is nearly singular (ill-conditioned) due to multicollinearity
- You have more features than observations ()
- The dataset is very large
In these cases, numerical methods like QR decomposition, SVD, or gradient descent are preferred for stability and efficiency.