Online Learning Systems
Building ML models that learn incrementally from streaming data — from online gradient descent through bandit algorithms, streaming features, and production deployment.
When to Use
- Data arrives as a stream (real-time, high volume)
- Models must adapt to changing distributions quickly
- Training on all historical data is too expensive
- Building bandit systems for real-time optimization
Online Learning Algorithms
class OnlineSGD:
"""Online Stochastic Gradient Descent."""
def __init__(self, n_features: int, lr: float = 0.01):
self.weights = np.zeros(n_features)
self.lr = lr
def partial_fit(self, x: np.array, y: float):
"""Update model with one sample at a time."""
pred = np.dot(self.weights, x)
self.weights += self.lr * (y - pred) * x
def predict(self, x: np.array) -> float:
return np.dot(self.weights, x)
Common Pitfalls
- Concept drift — online learning adapts slowly to sudden shifts
- Catastrophic interference — new data can overwrite useful old patterns
- No baseline — compare with periodically retrained batch model
- Cold start — warm-start with mini-batch from historical data
Verification Checklist
- Algorithm supports incremental updates (partial_fit)
- Feature computation consistent in training and serving
- Concept drift detection integrated
- Model checkpointing for recovery