Online Logistic Regression

Machine Learning
Introduced by
Rosenblatt, F. / Widrow, B. (perceptron era); modern SGD form: Bottou, L.
Year
1960s (perceptron); formalized for logistic loss ~2000s
Type
Incremental supervised classifier
Family
Machine learning

What does it do?

Online Logistic Regression fits a logistic classifier one observation at a time using stochastic gradient descent, updating the weights as each observation arrives instead of waiting for the full dataset.

It is a common choice for high-volume or streaming binary classification problems where batch training is impractical.

The intuition behind the method

Batch logistic regression loads all the data and optimizes over the whole dataset at once. Online logistic regression instead reads each incoming example, predicts its probability of the positive class, measures the error, and takes one small gradient step to correct its weights before the next example arrives. Over many examples the weights move toward a solution similar to what a batch solver would reach, but they fluctuate more around it, so the result is noisier than a converged batch fit on the same data. The learning rate is reduced over time so that later updates make smaller corrections and the weights settle rather than oscillate. That settling suits stationary data, but it also slows the model's response when the class boundary moves.

History

Online gradient-based learning has antecedents in early linear update rules such as Rosenblatt's perceptron and the Widrow and Hoff LMS rule. These are not logistic-loss methods and are mentioned only for context. The logistic-loss version rests on the general stochastic gradient descent and online convex optimization literature, with Bottou's work on large-scale stochastic gradient descent and Shalev-Shwartz's survey of online convex optimization as key references. Shalev-Shwartz notes that large-scale applications such as online advertisement placement and web ranking have driven interest in online learning, where data arrive continuously and models must be updated as predictions are made.

When to use it

Use Online Logistic Regression when data arrive as a stream or when the full dataset is too large to hold in memory, when low-latency model updates are required, or when the class boundary may shift over time (concept drift) and the learning rate is kept from decaying to zero. It is also a fast baseline for very large static datasets where a single SGD pass is acceptable. Avoid it when the dataset is small enough to batch-train (batch logistic regression will converge to a better solution with less tuning), when the decision boundary is highly nonlinear (tree-based or kernel methods will fit better), or when interpretability of exact coefficient standard errors and p-values is required for reporting.

Limitations and considerations

  • Sensitive to learning-rate choice: too large causes divergence, too small causes slow convergence or underfitting.
  • Does not provide closed-form confidence intervals or p-values for coefficients.
  • Converges to a noisier solution than batch gradient descent given the same data; multiple passes or averaging (Polyak-Ruppert) are needed to close the gap.
  • Performance degrades when features are on very different scales unless standardization or AdaGrad is applied.
  • Assumes a linear decision boundary; cannot capture nonlinear structure without feature engineering.
  • Under the inverse-time schedule the learning rate shrinks toward zero as the stream grows, so the model's ability to track drift weakens over time unless the rate is floored.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Constant memory with respect to the number of examples: each observation is processed once and discarded, so only the weight vector is stored.
  • Can adapt to concept drift because the weights keep updating as newly labeled examples arrive; this requires a learning rate that does not decay to zero, since the inverse-time schedule otherwise freezes the weights.
  • Suitable for datasets too large to hold in memory, since training needs one pass over the stream rather than repeated access to all the data.
  • Predicted probabilities come from the sigmoid link and can be used directly as scores, though they are not guaranteed to be well calibrated.
  • The L2 penalty is part of the update rule shown in the formulas; L1 regularization needs specialised updates such as truncation or FOBOS to keep weights exactly sparse.

Applications

  • Click-through-rate prediction in online advertising with continuous data streams.
  • Spam and fraud detection where patterns evolve and models must adapt daily.
  • Real-time sentiment classification of social-media posts as they arrive.
  • Large-scale binary risk scoring when the full dataset does not fit in RAM.
  • Concept-drift scenarios in financial transaction monitoring.
  • Baseline streaming classifier before evaluating more complex online ensembles.

How it works

How it works

1

The weight vector and bias start at zero, as in the initialization step of the formulas. No pass over the data is needed first, so the model can process its first observation immediately.

Formula
\mathbf{w}_0 = \mathbf{0},\; b_0 = 0
2

For each incoming observation the model computes the linear combination of its current weights and features, then passes it through the sigmoid function to obtain a probability that the label is 1. This probability is used both as the prediction and as an ingredient in the gradient computation.

Formula
\hat{p}_t = \sigma(\mathbf{w}_t^\top \mathbf{x}_t + b_t),\quad \sigma(z)=\frac{1}{1+e^{-z}}
3

The binary cross-entropy (log-loss) between the predicted probability and the true label measures how wrong the current prediction is. The log-loss is convex in the weights, so with suitably decreasing step sizes SGD can converge toward a global minimum, although a single update is not guaranteed to reduce the loss on every example.

Formula
\ell_t = -[y_t \log \hat{p}_t + (1-y_t)\log(1-\hat{p}_t)]
4

For this loss, the gradient with respect to the weights reduces to the residual (predicted probability minus true label) times the feature vector. The update formula includes an L2 penalty term, which shrinks the weights toward zero and limits overfitting. Each step multiplies the weights by approximately (1 - eta_t lambda) before the residual correction is applied, so lambda and the learning-rate schedule together set how strongly the weights are pulled toward zero, and this shrinkage accumulates over the stream. The bias is updated with the same residual but without the penalty, because the penalty applies to the weights only. Each example contributes one update, so the weights change in a single pass through the data stream.

Formula
\mathbf{w}_{t+1} = \mathbf{w}_t - \eta_t (\hat{p}_t - y_t)\mathbf{x}_t - \eta_t \lambda \mathbf{w}_t
5

The learning rate is annealed over time using the inverse-time form in the update formula. It starts large for fast early progress and shrinks so that later updates make finer corrections. When alpha is positive, the rate tends to zero as t grows, so this schedule suits stationary data. For a drifting stream the rate must stay above zero, for example by holding it at a minimum value, so the model can keep tracking changes. AdaGrad-style per-feature adaptation is an alternative that reduces sensitivity to features measured on very different scales, although its per-feature rates also shrink over time.

Formula
\eta_t = \eta_0 / (1 + \alpha t)

Common pitfalls

  • Forgetting to standardize features: online SGD is especially sensitive to scale differences because the same learning rate is applied to all dimensions.
  • Using a constant learning rate on stationary data: weights oscillate near the optimum and never settle. Conversely, a schedule that decays to zero on a drifting stream freezes adaptation, so the rate must be chosen to match whether the data are stationary.
  • Ignoring class imbalance in the data stream: under-represented classes receive few gradient signals and the model skews toward the majority class.
  • Treating early-phase weight estimates as final: the model needs sufficient examples before its weights stabilize; do not evaluate too early.
  • Confusing online-update capability with automatic concept-drift detection: weights drift with the data but explicit drift monitoring (e.g., ADWIN) is still needed to detect abrupt shifts.

Frequently asked questions

How does online logistic regression differ from standard logistic regression?

Standard logistic regression uses all data at once (batch optimization) and returns exact maximum-likelihood coefficients with standard errors. Online logistic regression updates weights after each example, using only constant memory and tolerating infinitely long streams, but its estimates are noisier and it does not produce inferential statistics.

How do I choose the learning rate?

Start with a small initial rate and a decaying schedule such as the inverse-time form in the update formula, or use AdaGrad, which adjusts per-feature rates automatically; AdaGrad's rates also shrink over time, so the same caveat applies. Standardize features first, then tune the initial rate on a held-out validation fold or by tracking the running log-loss over a recent window of the stream. Use a decaying rate when the data are stationary so the weights settle. When the stream drifts, keep the rate from decaying to zero, for example by holding it at a minimum value, and tune that minimum to the expected rate of change in the data.

Can online logistic regression handle multiclass problems?

Yes — extend it to one-vs-rest binary classifiers trained in parallel, or use the softmax (multinomial) generalization with categorical cross-entropy loss and per-class weight vectors, applying the same SGD update rule to each.

What regularization should I use?

L2 (ridge) regularization is the default: it shrinks all weights smoothly and plays well with SGD. Each update multiplies the weights by approximately (1 - eta_t lambda) before the gradient correction, so lambda and the learning-rate schedule together set the penalty strength, and the shrinkage accumulates over the stream. Tune lambda jointly with the initial learning rate on a validation or prequential window, and standardize features first so that a single lambda treats them comparably. L1 (lasso) produces sparse weights and is useful when you want automatic feature selection in very high-dimensional spaces, but requires careful truncation or FOBOS updates to stay exactly sparse online.

How do I evaluate a model that is continuously updated?

Use prequential (test-then-train) evaluation: predict each example before using it for a weight update, then report the running log-loss or AUC over a sliding window. This gives an online estimate of predictive performance as the model learns. Because the model changes between predictions, the estimate reflects the learning trajectory rather than one fixed model, so pair it with a sliding window and, where a stable comparison is needed, a periodic fixed holdout set.

Related methods

Sources

  1. Bottou, L. (2010). Large-Scale Machine Learning with Stochastic Gradient Descent. In Proceedings of COMPSTAT 2010, 177–186. Physica-Verlag.

    Open publication reference
  2. Shalev-Shwartz, S. (2012). Online Learning and Online Convex Optimization. Foundations and Trends in Machine Learning, 4(2), 107–194.

    Open DOI reference