Lec 13: Nearest Neighbor Algorithms

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play

1/15

encourage image

There are no tags or description

Looks like no tags are added yet.

16 Terms

1
New cards

Nearest neighbor learning (kNN)

store labeled training examples and predict a new instance’s label using the closest previous examples

2
New cards

Steps for single nearest neighbor

  1. data, D, consisting of tuples (vectors) of features (𝑥_𝑖 ) ⃗ and labels 𝑓((𝑥_1)) ⃗

  2. find the training example with the smallest distance to the new review

  3. give the new review the same label as its nearest neighbor


3
New cards

Eager Learning vs. Lazy Learning

Eager learns a model ahead of time

Lazy stores examples and delays computation until prediction

4
New cards

what are 4 things needed for kNN?

Distance metric: determines how similar 2 reviews are

Number of neighbors k: determines how many examples to consider

weighting function: determines how important each neighbor is

output rule: majority vote or avg

5
New cards

classification vs. regression

classification: take the majority vote of the neighbors’ labels

regression: take the average of the neighbor’ numerical outputs

6
New cards

k is too small vs too large

small k: sensitive to noise, overfitting

large k: blurred boundaries, underfitting

7
New cards

weighted kNN

give closer neighbors more influence than distant neighbors

classification: weighted majority vote

regression: weighted average

8
New cards

Advantages and disadvantages of kNN

Advantage: fast training, if we add 100 more data right now it wouldn’t need a new math model and can just add it to the database so it is flexible

disadvantage: slow prediction, high storage, sensistive to irrelevant features. everytime someone submits something for review, we need to compare it against thousands of stored reviews

9
New cards

what is the difference between kNN and k-means

kNN is supervised and predicts labels from k neighbors: labeled data, compare the query to indivdual reviews

k-means is unsupervised and discvoeres k clusters, compare query to cluster centroids

10
New cards

what is clustering

Grouping similar unlabeled data points using their features and a distance metric

11
New cards

Feature vector

A numerical representation of an instance, with each feature corresponding to one dimension. Example: (5,1).

12
New cards

Euclidean distance

Example

since 1 is smaller than 13, A is more similar to our new data

formula:


13
New cards

K-means algorithm

to initialize k-means: choose the number of clusters k and initialize k centroid locations, typically randomly

calculate a cluster centroid: average each feature across all points assigned to that cluster

  • Assign: Calculate distances to determine which cluster each point belongs to using eucledian

  • Update: Average the coordinates of the points in each cluster to find the new centroid.

  • repeat until Nobody changes clusters! Therefore, the algorithm has converged, and we can stop.


14
New cards

Limitations of k-means

Must specify k; sensitive to initialization; may get stuck in poor solutions; clusters may lack meaning.

15
New cards

How do you classify a new instance after k-means clustering?

Calculate its distance to each centroid and assign it to the nearest cluster.

16
New cards

How do we estimate cluster confidence, and how does k-means define categories?

Compare closest and next-closest centroid distances. Smaller ratio means greater relative confidence. Categories are defined by centroids.