Instance-Based Learning

What is the difference between instance-based and model-based learning?

Model-based learning builds a model during training, while instance-based learning keeps the examples and compares new inputs to them when predicting.

On this page
  1. Short answer
  2. How model-based learning works
  3. How instance-based learning works
  4. A house price example
  5. Key differences
  6. Which one suits your problem?
  7. Hybrid approaches
  8. The core question each approach asks

Short answer

Model-based learning fits a model during training and then predicts with that model. Instance-based learning keeps the training examples and, when a prediction is needed, compares the new input with them. One approach builds a compact model of the data. The other keeps the data and looks at the most similar examples when asked.

How model-based learning works

A model-based method chooses a model family, such as a straight line or a decision tree, then adjusts the model’s internal values so it fits the training data as closely as it can. Common examples include:

  • Linear regression, which learns a slope and an intercept for predicting a number.
  • Logistic regression, which learns weights for predicting the probability of a class.
  • Decision trees, which learn a set of if-then splits on the input features.
  • Neural networks, which learn many weights across layers.

Once training is done, the model can make predictions without the original training examples.

How instance-based learning works

Instance-based methods do little or no training. They store the labeled examples, and when a new input arrives they:

  1. Measure how similar the input is to each stored example.
  2. Pick the few nearest examples.
  3. Combine their labels by vote or by average.

The best-known example is k-nearest neighbors (k-NN). For more worked examples, read instance-based learning in machine learning examples.

A house price example

Suppose you have records of past home sales, each with a size and a sale price.

A model-based approach fits a line through those records. It might learn a rule of the form “price is roughly a base amount plus a fixed amount per square meter.” To predict the price of a new house, you apply that rule. The sales records are no longer needed for the prediction.

An instance-based approach stores every sale. To predict the price of a new house, it finds the five sales most similar in size and averages their prices. Adding a new sale just means adding another record to the stored set. The sales records must be kept, and each prediction searches them.

Key differences

Model-based Instance-based
What is kept after training Learned parameters or structure The training examples
When most of the work happens During training At prediction time
Prediction speed Typically fast once trained Can slow down as data grows, unless indexed
Memory needs Usually small Grows with the dataset
Adding new data Often needs retraining or an update Add the example to the stored set
Explaining a prediction Inspect the weights or rules, for simple models Point to the similar examples used
Typical methods Linear and logistic regression, decision trees, neural networks k-nearest neighbors, case-based reasoning

Which one suits your problem?

Model-based methods tend to suit large datasets, tight speed requirements, or cases where you want a compact model you can deploy and inspect.

Instance-based methods suit modest datasets where similarity is meaningful, where the data changes often, and where the cost of searching the stored examples is acceptable.

No method wins everywhere. The no free lunch rule in machine learning says that, averaged over all possible problems, no algorithm does better than another. Compare both approaches on held-out data before you choose.

Hybrid approaches

Some systems mix the two ideas. A neural network can turn images or text into numeric vectors, and a search then finds the stored vectors closest to a query. The network is a learned model, while the lookup works like instance-based learning.

The core question each approach asks

Model-based learning asks, “What general rule fits this data?” Instance-based learning asks, “Which past examples look most like this one?”

The complete guide to instance-based learning

Instance-Based Learning in Machine Learning With Examples
Read the guide

Keep exploring

Guides from other topics

All topics →