Portfolio Assignment 14

k-Nearest Neighbor Classifiers

Task: Implement a simple k-nearest neighbor classifier

Chapter 8 of our Collective Intelligence book attempts to build a price-predicting model using a k-nearest neighbor classifier.

Specific Tasks

For this assignment, focus on implementing all the code from pages 167 - 188 using the provided numpredict.py to get you started.

  1. Be sure to have read DM pages 223 - 227 and CI pages 167 - 188.
  2. Implement the functions knnestimate(), inverseweight(), subtractweight(), guassian(), weightedknn(), crossvalidate(), and rescale()
  3. Using matplotlib, generate the probability density graph demonstrated in figure 8-11 (p188). Talk to me if you need help.
  4. In your own words, explain how the k-NN classifier works and why we've chosen to weight the calculations of nearest neighbors.