# Online/incremental Learning

A Machine Learning concept (Features & pipeline) in the LuxAlgo Library, with 1 indicator implementation.

## What is Online/incremental Learning?

Online, or incremental, learning updates a model continuously as new data arrives instead of refitting it on a stored batch. Each bar runs the same loop: the model predicts, the realized value reveals an error, and the parameters take a small corrective step. Algorithms built for this regime include least mean squares (LMS) and its normalized variant (NLMS), recursive least squares (RLS), and stochastic gradient descent. They need constant memory and constant work per bar, so they run comfortably inside an indicator.

The algorithms are older than machine learning's modern branding. Frank Rosenblatt's perceptron (1958) learned from one example at a time, and Bernard Widrow and Ted Hoff published the least-mean-squares rule in 1960 to train their ADALINE machine. Stochastic gradient descent, the workhorse behind modern [neural networks](https://www.luxalgo.com/library/concept/neural-networks/), descends from Robbins and Monro's 1951 work on stochastic approximation, and recursive least squares comes from classical estimation theory. Even [PCA](https://www.luxalgo.com/library/concept/pca/) has an online form: Oja's rule (1982) learns a principal component one observation at a time.

The appeal for markets is drift: relationships between features and returns change, and an incremental model tracks the current relationship rather than an average over years. The cost is a tuning knob, the learning rate or forgetting factor, that trades stability for responsiveness. Update too fast and the model chases noise; too slow and it lags regime change, the same dilemma every adaptive parameterization scheme faces. Nothing about the update rule guarantees the tracked relationship persists.

Online learning changes how a model is fitted, not what it is fed. [Feature engineering](https://www.luxalgo.com/library/concept/feature-engineering/) still decides what the model sees, and the [label definition and prediction horizon](https://www.luxalgo.com/library/concept/label-definition-and-prediction-horizon/) still decide what it is asked to track; the updater merely keeps the mapping between the two current. Nor does it abolish overfitting: an aggressive learning rate can fit the last dozen bars beautifully and predict nothing. The consolation is that online models are walk-forward by construction: each prediction is made before the model sees the outcome that will update it.

## How to recognize online learning in an indicator

Online learning is a fitting procedure rather than a chart pattern, so it shows up in an indicator's settings and behavior instead of in price structure.

1. Check the inputs: a learning rate, step size, or forgetting factor is the signature of a per-bar updater such as LMS, NLMS, RLS, or stochastic gradient descent.
2. Watch the response to a shock: an online fit visibly re-converges over the following bars at a speed set by that knob, whereas a fixed moving average always lags by the same amount.
3. Confirm the output is causal: past values should not rewrite as new bars arrive. If history reshapes itself, the script is refitting on the whole visible window, which is batch behavior.
4. Stress-test the knob by halving and doubling it: a sound implementation trades smoothness for responsiveness gracefully instead of flipping between chase and lag.

## How traders use it

- As adaptive smoothing and forecasting: filter coefficients update each bar so the fitted line or one-step-ahead forecast keeps tracking current conditions, in the same family as the Kalman filter.
- As drift handling for signal models: a classifier or regression updated incrementally weights recent behavior more, avoiding the stale fit of a frozen training window.
- As a lightweight alternative to periodic refits: constant per-bar cost replaces scheduled batch retraining, which matters inside charting environments with tight compute limits.
- As rolling signal calibration: a [logistic calibration](https://www.luxalgo.com/library/concept/logistic-signal-calibration/) whose coefficients update with each resolved trade attaches probabilities that reflect recent rather than ancient performance.
- As adaptive weighting in ensembles: [ensemble voting](https://www.luxalgo.com/library/concept/ensemble-voting-of-signals/) schemes can adjust member weights bar by bar, shifting influence toward components that have been right lately.
- As a partner for regime models: paired with a [regime-switching model](https://www.luxalgo.com/library/concept/hidden-markov-markov-switching-regimes/), the learning rate can be raised or the fit reset when a transition is flagged, on the logic that data from the old regime has stopped being representative.

## Online learning vs other model-fitting approaches

- **Kernel Regression** (https://www.luxalgo.com/library/concept/kernel-regression/): Kernel regression refits a smooth curve over a stored window of data on every bar; an online learner stores no window and folds each observation into a few coefficients. The kernel fit is more flexible in shape, the online fit lighter and adaptive through its forgetting mechanism.
- **kNN Analog Forecasting** (https://www.luxalgo.com/library/concept/knn-analog-forecasting/): kNN keeps every historical example and searches that memory at prediction time, so its knowledge grows with history. Online learning compresses history into fixed parameters: it can never recall a specific past episode, while kNN can, at the cost of memory and lookup work.
- **Random Forest** (https://www.luxalgo.com/library/concept/random-forest/): A classic random forest is a batch learner: adapting it means retraining on a stored dataset. It captures nonlinear interactions that linear online filters cannot, but between retrains it is frozen, whereas an online model adjusts on every bar.

## FAQ

### What is the difference between online learning and batch retraining?

Batch retraining refits the model from scratch on a stored window at intervals, so it adapts in steps and needs the full dataset each time. Online learning folds each new observation into the parameters immediately and can then discard it, adapting continuously with constant memory. Batch fits are usually more stable; online fits react faster but are more exposed to noisy updates.

### Why use a forgetting factor in recursive least squares?

The forgetting factor down-weights old observations geometrically so the fit reflects recent conditions rather than the entire history. Values near 1 change the model slowly and smooth out noise; smaller values adapt quickly but can overreact to a few unusual bars. It is a stability-versus-responsiveness dial, no setting suits every regime, and sensitivity checking is worth the effort.

### Do online learning indicators repaint?

A correct implementation does not: each bar's output uses only information available at that bar and stays fixed once printed. If an adaptive indicator's history redraws as new data arrives, it is refitting the whole window, which is batch behavior and flatters the backtest; bar-replay testing is a quick check.

### What is the difference between LMS and RLS?

Both update a linear model on every observation. LMS takes a small gradient step scaled by a learning rate: cheap, robust, but slower to converge. RLS solves the exponentially weighted least-squares problem exactly at each step, adapting faster at higher per-bar cost and with more numerical fragility. NLMS, which normalizes the LMS step by input power, is a common middle ground.

### Can neural networks be trained online?

Yes. Stochastic gradient descent consumes examples one at a time, and the perceptron was an online learner from the start. The known hazard is catastrophic forgetting: adapting to recent data can overwrite what the network learned earlier, a real cost in markets where old regimes have a habit of returning.

## Implementations in the Library

- Recursive Least Squares Forecast (LuxAlgo): https://www.luxalgo.com/library/indicator/recursive-least-squares-forecast/

## Related concepts

- Feature Engineering: https://www.luxalgo.com/library/concept/feature-engineering/
- Feature Selection: https://www.luxalgo.com/library/concept/feature-selection/
- Train/validation Discipline: https://www.luxalgo.com/library/concept/train-validation-discipline/
- Logistic Signal Calibration: https://www.luxalgo.com/library/concept/logistic-signal-calibration/
- PCA: https://www.luxalgo.com/library/concept/pca/
- Label Definition & Prediction Horizon: https://www.luxalgo.com/library/concept/label-definition-and-prediction-horizon/
- Model Overfitting: https://www.luxalgo.com/library/concept/model-overfitting/
- Probability Calibration Curves: https://www.luxalgo.com/library/concept/probability-calibration-curves/

---

Source: https://www.luxalgo.com/library/concept/online-incremental-learning/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/