Docsity

Instance-Based Learning: Nearest Neighbor Algorithm and Applications, Exams of Computer Science

Toggle sidebar
bg1
1
Copyright 2005 by David Helmbold 1
Instance Based Learning
AKA: non-parametric, lazy,
memory-based, or case-based
learning
2
Non-parametric techniques
• Do not fit a model (as do LTU, decision
tree, etc)
• Includes Nearest Neighbor and density
estimation methods
• Variable sized hypothesis space, like
Decision trees
• “lazy” Hypothesis (no gradient descent,
optimization, or search) (under “\lazy” in Weka)
3
Nearest Neighbor Algorithm
• Instances (x’s) are vector of real
• Store the n training examples
(x1, y1), …, (xn, yn)
• To predict on new x, find xi closest to x and
predict with yi
• Comments:
– Not just simple table lookup
– Can avoid √b y minimizing squared distance
4
NN Decision Boundaries
• Vornoi diagram, very flexible, gets more
complicated with additional points
++
+
-
-
pf3
pf4
pf5
pf8

Partial preview of the text

Download Instance-Based Learning: Nearest Neighbor Algorithm and Applications and more Exams Computer Science in PDF only on Docsity!

Copyright 2005 by David Helmbold 1

Instance Based Learning

AKA: non-parametric, lazy,

memory-based, or case-based

learning

2

Non-parametric techniques

  • Do not fit a model (as do LTU, decision

tree, etc)

  • Includes Nearest Neighbor and density

estimation methods

  • Variable sized hypothesis space, like

Decision trees

  • “lazy” Hypothesis (no gradient descent,

optimization, or search) (under “\lazy” in Weka)

3

Nearest Neighbor Algorithm

  • Instances ( x ’s) are vector of real
  • Store the n training examples ( x 1 , y 1 ), …, ( x n, yn )
  • To predict on new x , find x i closest to x and predict with yi
  • Comments:
    • Not just simple table lookup
    • Can avoid by minimizing squared distance 4

NN Decision Boundaries

  • Vornoi diagram, very flexible, gets more

complicated with additional points

  • (^) +

- -

5

Nearest Neighbor Applications

  • Astronomy (classifying objects)
  • Medicine - diagnosis
  • Object detection
  • Character recognition (shape matching)
  • Many others (basic theory from1950’s

and 60’s)

6

Distance metric important

  • Consider expensive houses with features:
    • Number of bedrooms (1 to 5+)
    • Lot size in acres (1/6 to 1/2 plus tail)
    • House square feet (1200 to 3000+) Difference in square feet dominates
  • Irrelevant attributes (e.g. “how far away was owner born?”) add variability
  • Correlated attributes also bad 7

Irrelevant attribute example

  • Let x 1 ∈ [0,1] determine class, y = 1 iff x 1
  • Consider predicting on (0,0) given data

(0.1, x 2 ) labeled 0

(0.5, x’ 2 ) labeled 1

where x 2 , x’ 2 random draws from [0,1]

  • Chance of error ~ 15%! 8

Some tricks

  • Rescale attributes to mean 0 variance 1
  • Use wj on j th^ component:
    • Dist( x , x ’ ) = ∑ j wj ( x j - x ’j)^2
    • wj = I(xj, y) (“mutual information”)
  • Mahalanobis Distance (covariance Σ, like LDA)

Dist( x , x ’ )= ( x - x ’ )T^ Σ-1^ ( x - x ’ )

13

K-nearest neighbor

  • Algorithm: Find the closest k points and

predict with their majority vote

  • K-NN is Bayes optimal in limit as k and

training set size go to ∞ (known since

1960 ’s)

14

Edited NN

  • Key Idea: Reduce memory and computation by only storing “important” points
  • Heuristic:
    • Discard those points correctly predicted by others (or take incorrectly predicted points)
    • Remaining points concentrated on the decision boundary
  • Finding a smallest subset of points correctly labeling others is NP-complete. 15

Histogram method:

  • Break instance space X into bins
  • Use sample falling into bin to estimate probabilities
  • Histogram method is parametric, not

instance based

  • Has edge effects

Instance Based Density

Estimation

16

  • Smoother method: Add slice of

probability to area centered at example

rather than to predetermined bin

  • In general, have a Kernel function that

tells how probability added (see Duda

and Hart)

  • Gaussians common
  • Also called Parzon Windows
  • Often a “width” parameter controls smoothing (like σ in Gaussians)

17 distribution (^) sample bins (^) disks 18 distribution (^) σ= σ=5 (^) σ= 19

Final points

Can use smoothed nearest neighbor also (whole sample votes on predictions with weights depending on distance to new point), but may be computationally expensive Can fix k and use distance to kth nearest to estimate density Might use cross validation to estimate smoothing parameter Can use density estimation for P(x | class) and then predict class labels using Bayes’ rule 20

Nonparametric Regression

  • Aka smoothing models
  • Regressogram

! "

=

=

0 otherwise 1 if isinthesamebin with where 1 1 bx, x x^ x bx, x bx,x r gˆ x t^ t N t t N t t t

25 26 27

How to Choose k or h?

  • When k or h is small, single instances matter; bias is small, variance is large (undersmoothing): High complexity
  • As k or h increases, we average over more instances and variance decreases but bias increases (oversmoothing): Low complexity
  • Cross-validation is used to finetune k or h. 28

Tree and NN comparison

Training set no, but ok for test points Missing values Tricks Good with Good with knn pruning Noise/outliers Only in 1 or 2 dimensions interpretable If small tree Data mixed Usually Numeric Instance based, flexible Trees - flexible Model Decision Nearest Neighbor Trees

29

Tree and KNN Robustness

Lazy - expensive Computation OK time Irrelevant Fair Very bad features Monotone Great Very bad transformation Nearest neighbor Decision tree