- Introduced by
- Widrow, B. & Hoff, M. E. (LMS); Gauss / Plackett (RLS)
- Year
- 1960 (LMS); 1950 (RLS formalization)
- Type
- Incremental supervised regression
- Family
- Machine learning
What does it do?
Online Linear Regression fits a linear model one observation at a time, updating its weights as each new data point arrives.
Unlike batch least squares, it does not need to store or re-process the full dataset, which makes it suitable for streaming data, very large datasets, and settings where the underlying relationship may change over time.
The intuition behind the method
Think of adjusting a linear predictor after every single measurement rather than waiting to collect all the data first. Each new observation shows how wrong the current prediction was, and the weight vector is nudged a small step in the direction that would have reduced that error. With a suitably decaying learning rate on stationary data, the weights can approach the least-squares solution under standard conditions on the step-size schedule, yet the full dataset is never loaded into memory. On a finite stream, however, they are not guaranteed to match the OLS solution exactly. With a constant learning rate, the weights keep adapting, so the model can follow a relationship that drifts over time, though it will then fluctuate around the current best fit instead of settling.
History
Least-squares fitting originates with Gauss's least-squares method, and Plackett's 1950 recursive formulation is the basis for recursive least-squares methods. The practical online variant used here, the least mean squares (LMS) algorithm of Widrow and Hoff (1960), was developed for adaptive signal processing. Shalev-Shwartz's 2012 survey places online learning within online convex optimisation and emphasises the role of convexity in deriving efficient online learning algorithms.
When to use it
Use online linear regression when data arrive as a continuous stream and predictions must be made as observations come in, when the dataset is too large to hold in memory for a batch fit, or when the relationship between predictors and outcome may drift and the model must keep adapting. It is also a reasonable lightweight baseline in real-time systems. The method assumes that the relationship between predictors and outcome is approximately linear; a strongly misspecified linear model gives biased predictions however the weights are updated. Choose a decaying learning rate when the relationship is stationary and a constant rate when it is expected to drift, and standardise features before updating, because feature magnitude determines how large a step remains stable. Avoid online linear regression when the relationship is strongly nonlinear, when feature engineering must be done holistically over the full dataset, or when you need exact OLS coefficients with standard errors and confidence intervals for statistical inference; batch linear regression is the better choice in those cases.
Limitations and considerations
- Sensitive to the choice of learning rate: a value that is too large makes the weights oscillate, and one that is too small makes convergence slow.
- Correlated features slow the LMS update considerably, and without L2 regularisation the weights can become large and unstable on near-collinear data.
- Provides no closed-form standard errors or p-values, so classical statistical inference is not directly available.
- When all data are already available and the relationship is stationary, a batch OLS fit is exact and usually more efficient.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Processes data one observation at a time with memory that grows with the number of features p, so the full dataset never needs to be stored.
- A constant learning rate lets the weights keep tracking a changing relationship, which suits non-stationary streams such as financial tick data or sensor readings.
- Each update is a single dot product for prediction and one vector addition for the weight change, so the per-observation cost is low.
- Predictions are available immediately, without waiting for a batch re-fit.
Applications
- Real-time prediction of prices or demand in settings where observations arrive continuously.
- Adaptive filtering and noise cancellation, the setting in which the LMS algorithm was originally developed.
- Continuous model updating in sensor or IoT settings where periodic batch re-fits are impractical.
- Regression on financial tick data, where the underlying process may shift over time.
- Updating feature weights in streaming recommendation settings as user events arrive.
- A simple streaming baseline against which more complex online models can be compared.
How it works
How it works
Set the weight vector to zero, as in the update rule, and choose a learning rate eta > 0 that sets the step size. An L2 (Ridge) penalty can optionally be added to the update to limit weight growth, which matters most on sparse or non-stationary streams.
Formula
\mathbf{w}_0 = \mathbf{0},\; \eta > 0For each arriving observation x_t, compute the predicted output as the dot product of the current weight vector with the feature vector. This prediction is made before the true label y_t is revealed, mirroring the sequential nature of streaming settings.
Formula
\hat{y}_t = \mathbf{w}_t^\top \mathbf{x}_tAfter the true label is revealed, compute the squared prediction error. The gradient of the squared loss with respect to the weights is proportional to the error multiplied by the feature vector; the constant factor is absorbed into eta.
Formula
\ell_t = (y_t - \hat{y}_t)^2Apply the least mean squares (LMS) update: move the weights in the direction of the negative gradient of the loss. The step size eta controls the trade-off between adaptation speed and noise sensitivity. A smaller eta gives smoother but slower convergence, while a larger eta adapts faster but can oscillate.
Formula
\mathbf{w}_{t+1} = \mathbf{w}_t + \eta\,(y_t - \hat{y}_t)\,\mathbf{x}_tProcess the next observation immediately, applying the same update with no full re-fit. If the data are non-stationary, a constant learning rate lets the weights keep tracking changes, whereas a decaying rate suits stationary data, where it helps the weights settle. Drift-detection tests such as ADWIN can be used alongside the update to flag change, but they are separate from the update rule itself.
Common pitfalls
- Using a single learning rate on features with very different scales. Standardise features online, for example with running means and variances, before updating.
- Omitting regularisation in high-dimensional or near-collinear settings, which lets the weights grow on sparse or noisy streams.
- Treating the online weights as equivalent to OLS estimates and reporting them with OLS confidence intervals. The two are not the same, and the online weights carry no standard errors.
- Assuming the model adapts to drift without thought: with a constant learning rate it tracks changes but also tracks noise, and a decaying rate will not follow a sharp shift.
- Evaluating accuracy only at the end of a long stream instead of using prequential (test-then-train) evaluation throughout.
Frequently asked questions
How does online linear regression differ from standard (batch) linear regression?
Batch linear regression solves the normal equations on the entire dataset at once, giving the exact OLS solution. Online linear regression updates weights incrementally after each observation using a gradient step. Under suitable step-size conditions the weights can approach the least-squares solution without ever loading all the data, but the method does not provide the exact inference statistics that batch OLS gives.
What learning rate should I use?
No single learning rate is correct for every problem. Try a few values on an initial part of the stream and compare prequential error: too large a value makes the weights oscillate, and too small a value makes learning slow. Per-feature adaptive methods such as AdaGrad and Adam adjust the step size automatically and are often easier to tune than a single fixed rate.
Can online linear regression handle concept drift?
Yes, to a degree. A constant (non-decaying) learning rate keeps the model responsive to drift. For abrupt shifts, explicit drift-detection tests such as ADWIN can signal that the relationship has changed, so the weights can be adjusted or reset. A decaying rate is better when the relationship is stationary and you want the weights to settle.
Is regularisation possible in the online setting?
Yes. Adding an L2 penalty gives an online Ridge (Tikhonov) update: at each step the current weight vector is shrunk slightly before the gradient step is applied. This limits weight growth on sparse or noisy streams and is often used in high-dimensional settings.
How do I evaluate an online model fairly?
Use prequential (test-then-train) evaluation: record the prediction error on each observation before using it to update the model. This gives a sequential estimate of generalisation error without a separate held-out test set.
Related methods
Sources
Shalev-Shwartz, S. (2012). Online Learning and Online Convex Optimization. Foundations and Trends in Machine Learning, 4(2), 107–194.
Open DOI referenceHaykin, S. (2002). Adaptive Filter Theory (4th ed.). Prentice Hall.
ISBN: 978-0130901262