1/15
Looks like no tags are added yet.
Nearest neighbor learning (kNN)
store labeled training examples and predict a new instance’s label using the closest previous examples
Steps for single nearest neighbor
data, D, consisting of tuples (vectors) of features (𝑥_𝑖 ) ⃗ and labels 𝑓((𝑥_1)) ⃗
find the training example with the smallest distance to the new review
give the new review the same label as its nearest neighbor

Eager Learning vs. Lazy Learning
Eager learns a model ahead of time
Lazy stores examples and delays computation until prediction
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
classification vs. regression
classification: take the majority vote of the neighbors’ labels
regression: take the average of the neighbor’ numerical outputs
k is too small vs too large
small k: sensitive to noise, overfitting
large k: blurred boundaries, underfitting
weighted kNN
give closer neighbors more influence than distant neighbors
classification: weighted majority vote
regression: weighted average
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
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
what is clustering
Grouping similar unlabeled data points using their features and a distance metric
Feature vector
A numerical representation of an instance, with each feature corresponding to one dimension. Example: (5,1).
Euclidean distance

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

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.





Limitations of k-means
Must specify k; sensitive to initialization; may get stuck in poor solutions; clusters may lack meaning.
How do you classify a new instance after k-means clustering?
Calculate its distance to each centroid and assign it to the nearest cluster.
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.