SeriesMachine Learning5 / 20

Instance-Based Learning

Module 5 of CS 7641 - Machine Learning @ Georgia Tech. Lesson 4 of Supervised Learning Series.

What is Instance-Based Learning?#

Instance-Based Learning refers to a class of supervised learning algorithms which directly reference instances in the training data to generate results. As opposed to learning a model-based representation using the training data, we directly compare new instances to the training data in order to generate a prediction. This approach works well when training data is very large and diverse.

The simplest example of instance-based learning is a database lookup program. Given a set of training instances of the form <x,y><x, y>, we store instances in the database with keys corresponding to xx and values to yy. Given a new instance <xn,yn><x_n, y_n>, we compare xnx_n to our set of keys to generate the prediction y^n\hat{y}_n.

db-lookup

There are certain pros and cons to this approach:

Instead of our simple database lookup example, we will introduce a better defined instance-based learning algorithm in the following section.

K-Nearest Neighbors#

Definition + Algorithm#

The K-Nearest Neighbors (KNN) algorithm is similar to database lookup, but relies on the notion of similarity between instances to make predictions. Given a new instance xnx_n, we calculate the pairwise similarity between the new instance and each instance in our training dataset. Then, the kk most similar training instances inform the final prediction.

GIVEN:

  • Training Data D={xiyi}D = \begin{Bmatrix} x_i & y_i \end{Bmatrix}
  • Query Point qq
  • Distance Metric d(q,x)d(q, x)
  • Number of Neighbors kk

NN = {i:  d(q,xi)  k smallest}\begin{Bmatrix} i: ~~ d(q, x_i) ~~ k ~ \text{smallest} \end{Bmatrix}

In the case of classification, KNN predicts the mode of the most similar neighbors. For regression, KNN predicts the mean.

Hyperparameter Tuning#

As with other machine learning algorithms, KNN has a number of Hyperparameters which must be optimized specific to the task at hand:

In order to perform hyperparameter tuning, we should use either a train-test split or cross validation to train our various hyperparameter configurations on the training partition(s), then optimize over performance on the validation (test) set.

Complexity#

Let’s compare the time and space complexity of algorithm training and inference. Assume we are given training data as a set of nn sorted data points with only a single feature.

ALGORITHMTIME COMPLEXITYSPACE COMPLEXITY
1-NNLearning1n
Inferencelog(n)1
K-NNLearning1n
Inferencelog(n) + k1
Linear RegressionLearningn1
Inference11

Biases#

Recall that preference bias describes an algorithm’s reasoning for selecting one hypothesis over another. In the context of KNN, there are three main factors which influence preference bias:

Miscellaneous Points on ML#

The Curse of Dimensionality is a problem shared across supervised learning algorithms highlighting issues associated with high-dimensional data.

As the number of features or dimensions grows, the amount of data we need to generalize accurately grows exponentially.

Consider the following example:

The more features we add to the problem, the more data we require to adequately represent the input space.


(all images obtained from Georgia Tech ML course materials)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts