Given a set of observations
The approach is fundamental because:
- It has a closed-form solution (the normal equation), so no iterative optimization is needed.
- It provides a baseline model against which more complex methods are measured.
- The solution is the maximum likelihood estimator under Gaussian noise assumptions.
This library solves the normal equation directly using Gaussian elimination, making it suitable for small-to-moderate feature counts typical in embedded estimation tasks.
In matrix form, augmenting
where
Minimizing
This is solved in practice by forming
The prediction
| Phase | Time | Space | Notes |
|---|---|---|---|
| Dominated by matrix multiply | |||
| Matrix-vector multiply | |||
| Solve | Gaussian elimination | ||
| Predict | Dot product |
For embedded use with small
Data: 3 samples, 1 feature.
| 1 | 2 |
| 2 | 4 |
| 3 | 5 |
Step 1 — Design matrix (with bias column):
Step 2 — Compute
Step 3 — Solve $\begin{bmatrix} 3 & 6 \ 6 & 14 \end{bmatrix} \boldsymbol{\beta} = \begin{bmatrix} 11 \ 23 \end{bmatrix}$:
Forward elimination → back-substitution:
Result:
Prediction at
-
Multicollinearity. If features are nearly linearly dependent,
$\mathbf{X}^T\mathbf{X}$ is ill-conditioned and the solution is unstable. Consider regularization (Ridge/Lasso) or removing redundant features. -
Fewer samples than features (
$n < p+1$ ). The system is underdetermined and$\mathbf{X}^T\mathbf{X}$ is singular. At a minimum,$n \geq p+1$ . - Outliers have outsized influence because the squared loss amplifies large residuals. Robust alternatives (Huber loss, RANSAC) exist outside this library.
- Extrapolation danger. The linear model has no mechanism to detect when it is being queried far from the training data range.
-
Fixed-point precision. For Q15/Q31 types, features should be scaled to
$[-1, 1)$ to avoid overflow in$\mathbf{X}^T\mathbf{X}$ .
| Variant | Key Difference |
|---|---|
| Ridge regression (L2) | Adds |
| Lasso regression (L1) | Adds |
| Polynomial regression | Adds powers of |
| Weighted least squares | Weights each sample differently; solves |
| Recursive least squares | Updates |
- Sensor calibration — Fitting a linear transfer function between raw ADC counts and physical units.
- Trend estimation — Extracting linear trends from noisy time series (temperature, voltage drift).
- System identification — Estimating static gain or simple dynamic relationships.
-
Feature importance — The magnitude of
$\beta_i$ indicates the influence of feature$i$ (after feature scaling). - Predictive maintenance — Modeling degradation rate from operating-condition features.
graph LR
LR["Linear Regression"]
GE["Gaussian Elimination"]
YW["Yule-Walker"]
NN["Neural Network"]
LR --> GE
YW -.->|"similar normal-equation structure"| LR
NN -.->|"single linear layer = regression"| LR
| Algorithm | Relationship |
|---|---|
| Gaussian Elimination | Used to solve the normal equation system |
| Yule-Walker | Structurally similar — also solves a linear system derived from correlations |
| Neural Network (neural-network-toobox-cpp) | A single-layer neural network with no activation and MSE loss reduces to linear regression |
- Hastie, T., Tibshirani, R. and Friedman, J., The Elements of Statistical Learning, 2nd ed., Springer, 2009 — Chapter 3.
- Bishop, C.M., Pattern Recognition and Machine Learning, Springer, 2006 — Chapter 3.
- Strang, G., Linear Algebra and Its Applications, 4th ed., Thomson, 2006 — Section 4.3.