DEV Community

Cover image for Online Machine Learning
Damika-Anupama
Damika-Anupama

Posted on

Online Machine Learning

The concept of online learning emerged in the early 1990s, influenced by the increasing availability of real-time data and the need for models that adapt without retraining on full datasets. The Perceptron algorithm, introduced in the 1950s, laid the groundwork for modern online learning methods. Online machine learning is a learning paradigm in which the model learns progressively in real time by processing input points sequentially. As new data comes in, the model is updated continuously, which enables it to dynamically adjust to changing data distributions without requiring a full dataset retraining. This method works especially well in situations when data is streamed or varies over time.

There are few key characteristics:

  1. Incremental learning involves updating the model with each new data point without the need to re-train on the entire dataset.
  2. Real-time Adaptation is a crucial feature that allows a model to quickly adapt to continuous data arrivals.
  3. The system efficiently reduces memory and computation costs by processing one data point at a time.

Online Learning vs Batch / Offline Learning
image description: Online Learning vs Batch / Offline Learning, source: https://www.linkedin.com/pulse/types-machine-learning-techniques-training-method-based-sharma/

Few use cases of Online Learning,

  • Real-time stock market predictions to analyze the most recent market data
  • Online advertising and click-through rate prediction
  • RL agent to predict the relevant insulin amount for a short time horizon, according to the real-time glucose level of type 1 diabetes patient
  • Spam filtering and network intrusion detection systems. As new patterns of spam or cyber-attacks emerge, the models are continuously updated to improve accuracy, ensuring timely detection of malicious activities with minimal manual intervention.

Meanwhile, here are few advantages and disadvantages in this learning paradigm.
Advantages:

  1. Since small amounts of data are processed, this reduces resource requirements and improves memory efficiency and computation.
  2. Suitable for cases in which data is delivered continuously, such as streaming data.
  3. Capable of responding to changes in the non-stationary data distribution over time.
  4. The model's fast updates, assisted by the availability of new data, allow for quick responses to changes in data trends, particularly in dynamic situations.

Disadvantages:

  1. Small batches might introduce fluctuations, making them susceptible to noise.
  2. In comparison to batch learning (opposite of online learning), it may take longer to converge to an optimal solution.
  3. The learning rate and regularization parameters must be carefully tuned for performance.

Let's talk about the mathematical foundation of online learning. Gradient descent-based optimization methods are frequently employed, specifically stochastic gradient descent (SGD), which updates model parameters iteratively based on small batches or individual data points to minimize the objective function over time. Perceptron algorithm and Hoeffding tree (Streaming Decision Tree) are another algorithms that use online learning. Here's a sample code to demonstrate online learning to use SGD.

SGD with online learning code output

Above online learning with SGD code output, shows how accuracy of the model output may change with time, when new data samples are continuously coming. Check how above-mentioned advantages and disadvantages may apply to code, and output.

During online learning cumulative error rate is calculated by analyzing performance over time across all data points. This calculates how quickly the model adjusts to new patterns in the data. Memory efficiency relates to the processing of small data chunks. There are few related learning paradigms that crosses with ours:

  1. Batch Learning / Offline Learning: Whole dataset all at once during training, only making updates to the model after the dataset has been thoroughly examined. Compared to online learning, this method usually produces updates that are more accurate and reliable, but it uses more memory and processing power. Batch learning is less effective in dynamic or streaming situations where data is always changing, as it is less flexible than online learning when it comes to real-time adaptation to new data.
  2. Incremental Learning: Updates models incrementally as new data becomes available, retaining previous knowledge and incorporating new information. It's suitable for large datasets or computationally expensive scenarios, combining online learning and batch-based updates.
  3. Active Learning: Involves selecting the most informative data points for learning, useful in scenarios with limited data.

Finally, let's discuss some modern applications regarding online learning. Real-time recommendation systems like Netflix, Amazon use online learning to recommend content as user preferences evolve. Banks and financial institutions use online models to detect fraudulent transactions in real-time. Continuously updating models in self-driving cars handle new sensor data from changing environments.
Future directions of this learning paradigm include Adversarial Robustness, Federated Online Learning, and Online Deep Learning.

Top comments (0)