- Published on
- •8 min read
Learning Machines: How Models Remember, Adapt, and Predict
- Authors

- Name
- David Manufor
- @davemanufor
In our last post, we introduced machine learning and looked at one major axis of the ML taxonomy: training supervision. But once we decide to let data write our rules, how does the machine actually keep up with a constantly changing world? And how does it turn that raw data into accurate, real-world predictions?
The answers lie in how a model ingests its data and how it generalizes what it learns. Today, we’re breaking down the critical differences between Batch vs. Online Learning and Instance-based vs. Model-based Generalization so you can architect systems that don’t just work in the lab, but thrive in production.
Axes 2: Data Ingestion
This classification focuses on whether a machine learning system can learn incrementally from an incoming stream of data or if it needs to process everything all at once.
Batch Learning (Offline Learning)
In a batch learning system, the model is incapable of learning incrementally on the fly. It must be trained using the entire dataset all in one go.
Because this process is heavily resource-intensive, batch training is typically done offline. Once training is complete, the static model is deployed into production, and its performance is monitored.
The Catch: Model Drift
The biggest downside to batch learning is that the world changes, but a deployed batch model does not. Over time, its performance will inevitably degrade—a phenomenon known as model drift or data drift.
- High-Volatility Environments: A model predicting stock market trends or financial fraud will experience rapid drift because the underlying data changes constantly.
- Low-Volatility Environments: A model classifying leaf types or identifying cats and dogs might seem immune to drift, but it isn’t. Environmental contexts shift—camera technologies evolve, image formats change, lighting conditions vary, or people might start putting their pets in trendy outfits. You must always account for drift.
Managing Drift in Batch Systems
To fix a drifting batch model, you have to retrain it on newer data. However, you cannot just feed it the new data alone; you must retrain the model from scratch on a combined dataset of both the old and the new data. For enterprise systems dealing with massive datasets, this is incredibly expensive in terms of compute, memory, disk I/O, and capital. Consequently, batch learning is highly impractical for resource-constrained environments like smartphones or embedded systems.
Online Learning (Incremental Learning)
Online learning systems are designed to learn on the fly by ingesting a continuous stream of data. This data can be processed either as individual data points or in small groups called mini-batches.
Why Choose Online Learning?
- Dynamic Environments: It is ideal for rapidly changing environments where staying up-to-date is critical (e.g., TikTok's recommendation engine, stock market predictors, or spam filters).
- Resource Constraints: It is highly efficient for devices with limited computational power and memory, like smartphones. Because the model learns from data as it arrives, you don't need to load an entire massive dataset into memory at once.
The Crucial Variable: Learning Rate
A vital parameter in online learning is the learning rate—how fast the model should adapt to new data:
- High Learning Rate: The model adapts to new data rapidly, but at the cost of quickly forgetting older, foundational patterns.
- Low Learning Rate: The model possesses more "inertia." It retains historical knowledge well but will be slower to react to new trends.
The Risk of "Bad Data"
The greatest vulnerability of online learning is its susceptibility to data poisoning. If a system glitch, a sensor error, or a malicious actor injects bad data into the live stream, the model will instantly learn from it, degrading performance in real time.
Mitigation Strategies:
- Real-time Monitoring: Implement anomaly detection proxies between the data source and the model to catch and filter out outliers before they reach the system.
- Model Snapshots: Regularly back up historical states of the model so you can instantly roll back to a known "good" state if performance plummets.
Axes 3: Generalization
This classification looks at how a model actually takes what it has seen and applies that knowledge to brand-new, unseen data.
How ML Systems Generalize
├── Instance-Based (Memorize data -> Compare at runtime -> "Lazy")
└── Model-Based (Extract patterns -> Create formula -> "Eager")
Instance-Based Learning ("Lazy Learners")
Instance-based models don't actually learn a generalized set of rules. Instead, they memorize the training data. When it’s time to make a prediction, they look at the new data point, compare it to their memorized database, and use a measure of similarity to find the closest match. They are called lazy learners because they do virtually no work during training, saving all the heavy computational lifting for the prediction phase.
Examples:
- k-Nearest Neighbors (k-NN): To classify a new data point, the model looks at the k closest neighboring data points in the system and takes a majority vote.
- Case-Based Reasoning (CBR): Think of an IT help desk assistant. When a new ticket comes in, they search the archive for the most similar historical ticket and apply the exact same solution.
Model-Based Learning ("Eager Learners")
Model-based systems use the training data to build a generalized mathematical or logical model. During the training phase, the system tweaks its internal parameters to fit the data best. Once training is complete, the model discards the original dataset entirely—it only needs its newly calculated parameters to make future predictions. These are called eager learners because they do all their hard work during the training phase.
To find the perfect parameters, these models use performance measures during training:
- Utility Functions: Measure how good a prediction is.
- Cost Functions: Measure how bad a prediction is (this is the most common approach, where the goal is to minimize the cost).
Examples:
- Linear & Logistic Regression: Fits a line (or an S-curve for classification) through data points by calculating specific weights (θ) for each feature.
Example: Predicting house prices. Instead of scanning neighboring houses at runtime, the model instantly uses a pre-calculated formula:
Price=θ0+(θ1×Square Footage)+(θ2×Bedrooms)
- Decision Trees & Random Forests: Breaks down data into a tree-like architecture of logical splits.
Example: Automated credit card approvals. The system passes an applicant's financial profile through a pre-calculated tree of rules (e.g., "If Income > $50k, go left") to output an instant decision.- Neural Networks (Deep Learning): Adjusts millions of mathematical weights across interconnected layers of artificial neurons to map out highly complex patterns (like features in an image or context in text). Once trained, the model is simply a file of mathematical weights—it never needs to look at the original training images again.
Fitting the Curve: Linear Regression
The simplest and most elegant example of model-based generalization is Linear Regression. Instead of looking at neighboring data points every time it needs to estimate a value, a linear regression model calculates a mathematical formula.
If we want to predict a house’s resale price based on its square footage, the model fits a straight line through the training data points. The formula is a simple prediction hypothesis:
Where is the predicted price, is the square footage, is the bias (the y-intercept where the line hits the axis), and is the feature weight (the slope of the line).
During training, the algorithm adjusts the weights and using a cost function that measures how far the predicted line is from the actual data points. Once the algorithm finds the parameters that minimize this distance, the training data is discarded. The model is now just a formula, ready to make instant predictions for any new house size we feed it.
Putting it to Code: House Pricing with Scikit-Learn
Let’s see how this works in practice. We will use Python, numpy, and scikit-learn to train a linear regression model on a small, synthetic dataset of house sizes and prices.
# house_pricing.py
import numpy as np
from sklearn.linear_model import LinearRegression
# House sizes in square feet (features)
# Scikit-learn expects a 2D array for features
X = np.array([[1000], [1200], [1500], [1800], [2000], [2400]])
# Resale prices in thousands of dollars (labels)
y = np.array([250, 290, 350, 410, 450, 530])
# Initialize the Linear Regression model
model = LinearRegression()
# Train the model (fit the line to our data)
model.fit(X, y)
# Retrieve the learned parameters (theta_1 and theta_0)
theta_1 = model.coef_[0]
theta_0 = model.intercept_
print(f"Learned Bias (theta_0): {theta_0:.2f}")
print(f"Learned Weight (theta_1): {theta_1:.4f}")
# Make a prediction for a new house of 1600 sq ft
new_house_size = np.array([[1600]])
predicted_price = model.predict(new_house_size)[0]
print(f"Predicted price for a 1600 sq ft house: ${predicted_price:.2f}k")Running this code reveals that the model fits a line with an intercept () of 50.00 and a slope () of 0.2000. In plain English, the model learned that a house starts at a base price of $50,000, and each additional square foot adds exactly $200 to the value. When we ask it to predict the price of a 1600 square foot house, it does not search a database. It simply runs the math: . The output is $370,000.
Wrapping up
As we've seen, there is no single "correct" way to build a machine learning system. Choosing between batch and online learning, or instance-based and model-based generalization, comes down to understanding your constraints.
Before you write your next line of code, ask yourself: How fast is my data changing? What are my hardware limitations? And how much "inertia" does my model really need? Getting these architectural choices right early on will save you countless hours of debugging, system crashes, and retraining headaches down the road.
Part 3 of 5 in Learning Machines
Learning Machines: What learning actually means
For years, I wrote code by telling the computer exactly what to do. Shifting to machine learning means letting the data write the rules. This post explores what 'learning' actually means in code, using Tom Mitchell's equation and the supervision taxonomy.
Learning Machines: Why random_state=42 Isn't Enough
Why relying on random_state for reproducible train/test splits breaks the moment your dataset changes — and how hash-based splitting with MurmurHash3 gives you deterministic, stable assignments that survive new data.