“Nonparametric” “Nonparametric” methodsmethods

28
1 Machine Learning Machine Learning “Nonparametric” “Nonparametric” methods methods Eric Xing Eric Xing 10 10-701/15 701/15-781, Fall 2011 781, Fall 2011 Lecture 2, September 14, 2011 Reading: 1 © Eric Xing @ CMU, 2006-2011 Univariate prediction without using a model: good or bad? Nonparametric Classifier (Instance-based learning) Nonparametric density estimation K-nearest-neighbor classifier Optimality of kNN Spectrum clustering Clustering Graph partition and normalized cut The spectral clustering algorithm Very little “learning” is involved in these methods But they are indeed among the most popular and powerful “machine learning” methods 2 © Eric Xing @ CMU, 2006-2011

Transcript of “Nonparametric” “Nonparametric” methodsmethods

Page 1: “Nonparametric” “Nonparametric” methodsmethods

1

Machine LearningMachine Learning

“Nonparametric” “Nonparametric” methodsmethods

Eric XingEric Xing

1010--701/15701/15--781, Fall 2011781, Fall 2011

Lecture 2, September 14, 2011

Reading:1© Eric Xing @ CMU, 2006-2011

Univariate prediction without using a model: good or bad?

Nonparametric Classifier (Instance-based learning)Nonparametric density estimationp yK-nearest-neighbor classifierOptimality of kNN

Spectrum clusteringClusteringGraph partition and normalized cutThe spectral clustering algorithm

Very little “learning” is involved in these methods

But they are indeed among the most popular and powerful “machine learning” methods

2© Eric Xing @ CMU, 2006-2011

Page 2: “Nonparametric” “Nonparametric” methodsmethods

2

ClassificationRepresenting data:

H th i ( l ifi )Hypothesis (classifier)

3© Eric Xing @ CMU, 2006-2011

Clustering

4© Eric Xing @ CMU, 2006-2011

Page 3: “Nonparametric” “Nonparametric” methodsmethods

3

Supervised vs. Unsupervised Learning

5© Eric Xing @ CMU, 2006-2011

Decision-making as dividing a high-dimensional space

Classification-specific Dist.: P(X|Y)

),;()|(

111

1Σ=

=µrXp

YXp

);()|( 2Σ=

=µrXp

YXp

Class prior (i.e., "weight"): P(Y)

),;( 222 Σ= µXp

6© Eric Xing @ CMU, 2006-2011

Page 4: “Nonparametric” “Nonparametric” methodsmethods

4

The Bayes Decision Rule for Minimum Error

The a posteriori probability of a sample

)|()()|( iYXiYPiYX

Bayes Test:

Likelihood Ratio:

)()|(

)|()(

)()|()|( XqiYXp

iYXpXp

iYPiYXpXiYP ii ii

ii ≡=

==

====

∑ ππ

Discriminant function:

=)(Xh

=)(Xl

7© Eric Xing @ CMU, 2006-2011

Example of Decision RulesWhen each class is a normal …

We can write the decision boundary analytically in some cases … homework!!

8© Eric Xing @ CMU, 2006-2011

Page 5: “Nonparametric” “Nonparametric” methodsmethods

5

Bayes ErrorWe must calculate the probability of error

the probability that a sample is assigned to the wrong classp y p g g

Given a datum X, what is the risk?

The Bayes error (the expected risk):

9© Eric Xing @ CMU, 2006-2011

More on Bayes ErrorBayes error is the lower bound of probability of classification error

Bayes classifier is the theoretically best classifier that minimize probability of classification errorprobability of classification errorComputing Bayes error is in general a very complex problem. Why?

Density estimation:

Integrating density function:

10© Eric Xing @ CMU, 2006-2011

Page 6: “Nonparametric” “Nonparametric” methodsmethods

6

Learning ClassifierThe decision rule:

Learning strategies

Generative Learning

Discriminative Learning

Instance-based Learning (Store all past experience in memory)A special case of nonparametric classifier

K-Nearest-Neighbor Classifier: where the h(X) is represented by ALL the data, and by an algorithm

11© Eric Xing @ CMU, 2006-2011

Recall: Vector Space Representation

Each document is a vector, one component for each term (= word)

Doc 1 Doc 2 Doc 3 ...Word 1 3 0 0 ...Word 2 0 8 1 ...Word 3 12 1 10 ...

... 0 1 3 ...

component for each term (= word).

... 0 1 3 ...

... 0 0 0 ...

Normalize to unit length.High-dimensional vector space:

Terms are axes, 10,000+ dimensions, or even 100,000+Docs are vectors in this space

12© Eric Xing @ CMU, 2006-2011

Page 7: “Nonparametric” “Nonparametric” methodsmethods

7

Test Document = ?

Sportsp

Science

Arts

13© Eric Xing @ CMU, 2006-2011

1-Nearest Neighbor (kNN) classifier

Sportsp

Science

Arts

14© Eric Xing @ CMU, 2006-2011

Page 8: “Nonparametric” “Nonparametric” methodsmethods

8

2-Nearest Neighbor (kNN) classifier

Sportsp

Science

Arts

15© Eric Xing @ CMU, 2006-2011

3-Nearest Neighbor (kNN) classifier

Sportsp

Science

Arts

16© Eric Xing @ CMU, 2006-2011

Page 9: “Nonparametric” “Nonparametric” methodsmethods

9

K-Nearest Neighbor (kNN) classifier

Sports

Voting kNN

p

Science

Arts

17© Eric Xing @ CMU, 2006-2011

Classes in a Vector Space

Sportsp

Science

Arts

18© Eric Xing @ CMU, 2006-2011

Page 10: “Nonparametric” “Nonparametric” methodsmethods

10

kNN Is Close to OptimalCover and Hart 1967Asymptotically the error rate of 1-nearest-neighborAsymptotically, the error rate of 1-nearest-neighbor classification is less than twice the Bayes rate [error rate of classifier knowing model that generated data]

In particular, asymptotic error rate is 0 if Bayes rate is 0.Decision boundary:

19© Eric Xing @ CMU, 2006-2011

Where does kNN come from?How to estimation p(X) ?

Nonparametric density estimation

Parzen density estimate

E.g. (Kernel density est.):

More generally:

20© Eric Xing @ CMU, 2006-2011

Page 11: “Nonparametric” “Nonparametric” methodsmethods

11

Where does kNN come from?Nonparametric density estimation

Parzen density estimate

kNN density estimate

Bayes classifier based on kNN density estimator:ayes c ass e based o de s ty est ato

Voting kNN classifier

Pick K1 and K2 implicitly by picking K1+K2=K, V1=V2, N1=N2

21© Eric Xing @ CMU, 2006-2011

Asymptotic AnalysisCondition risk: rk(X,XNN)

Test sample XpNN sample XNN

Denote the event X is class I as X↔I

Assuming k=1

When an infinite number of samples is available, XNN will be so close to X

22© Eric Xing @ CMU, 2006-2011

Page 12: “Nonparametric” “Nonparametric” methodsmethods

12

Asymptotic Analysis, cont.Recall conditional Bayes risk:

Thus the asymptotic condition risk

This is called the MacLaurin series expansion

It can be shown that

This is remarkable, considering that the procedure does not use any information about the underlying distributions and only the class of the single nearest neighbor determines the outcome of the decision.

23© Eric Xing @ CMU, 2006-2011

In fact

Example:

24© Eric Xing @ CMU, 2006-2011

Page 13: “Nonparametric” “Nonparametric” methodsmethods

13

kNN is an instance of Instance-Based Learning

What makes an Instance-Based Learner?

A distance metric

How many nearby neighbors to look at?

A weighting function (optional)

How to relate to the local points?

25© Eric Xing @ CMU, 2006-2011

Distance MetricEuclidean distance:

∑ xxxxD 22 )'()'( σOr equivalently,

Other metrics:L1 norm: |x-x'|

∑ −=i

iii xxxxD )'()',( σ

)'()'()',( xxxxxxD T −Σ−=

L∞ norm: max |x-x'| (elementwise …)Mahalanobis: where Σ is full, and symmetric CorrelationAngleHamming distance, Manhattan distance…

26© Eric Xing @ CMU, 2006-2011

Page 14: “Nonparametric” “Nonparametric” methodsmethods

14

Case Study:kNN for Web Classification

Dataset 20 News Groups (20 classes)20 News Groups (20 classes)Download :(http://people.csail.mit.edu/jrennie/20Newsgroups/)61,118 words, 18,774 documentsClass labels descriptions

27© Eric Xing @ CMU, 2006-2011

Experimental Setup

Training/Test Sets: 50% 50% randomly split50%-50% randomly split. 10 runsreport average results

Evaluation Criteria:

28© Eric Xing @ CMU, 2006-2011

Page 15: “Nonparametric” “Nonparametric” methodsmethods

15

Results: Binary Classesalt.atheism

vs.hi

Accuracycomp.graphics

rec.autos vs.

rec.sport.baseball

comp.windows.x vs.

rec.motorcycles

k

29© Eric Xing @ CMU, 2006-2011

Results: Multiple Classes

Accuracy

Random select 5-out-of-20 classes, repeat 10 runs and average

Accuracy

All 20 classes

k30© Eric Xing @ CMU, 2006-2011

Page 16: “Nonparametric” “Nonparametric” methodsmethods

16

Is kNN ideal? … more later

31© Eric Xing @ CMU, 2006-2011

Effect of ParametersSample size

The more the betterNeed efficient search algorithm for NN

Dimensionality Curse of dimensionality

DensityHow smooth?

MetricThe relative scalings in the distance metric affect region shapes.e e at e sca gs t e d sta ce et c a ect eg o s apes

WeightSpurious or less relevant points need to be downweighted

K

32© Eric Xing @ CMU, 2006-2011

Page 17: “Nonparametric” “Nonparametric” methodsmethods

17

Sample size and dimensionality

From page 316, Fukumaga33© Eric Xing @ CMU, 2006-2011

Neighborhood size

From page 350, Fukumaga34© Eric Xing @ CMU, 2006-2011

Page 18: “Nonparametric” “Nonparametric” methodsmethods

18

kNN for image classification: basic set-up

AntelopeTrombone?

Jellyfish

German Shepherd

Kangaroo

35© Eric Xing @ CMU, 2006-2011

5‐NN

Voting …

3

Count

? Kangaroo

Antelope Jellyfish German Shepherd TromboneKangaroo

3

2

1

0

36© Eric Xing @ CMU, 2006-2011

Page 19: “Nonparametric” “Nonparametric” methodsmethods

19

10K classes, 4.5M Queries, 4.5M training

sy: A

nton

io Torralba ?

Backgrou

nd im

age courtes

37© Eric Xing @ CMU, 2006-2011

KNN on 10K classes10K classes4 5M queries4.5M queries4.5M trainingFeatures

BOWGIST

Deng, Berg, Li & Fei‐Fei, ECCV 2010

38© Eric Xing @ CMU, 2006-2011

Page 20: “Nonparametric” “Nonparametric” methodsmethods

20

Nearest Neighbor Search in High Dimensional Metric Space

Linear Search:E.g. scanning 4.5M images!g g g

k-D trees:axis parallel partitions of the dataOnly effective in low-dimensional data

Large Scale Approximate IndexingLocality Sensitive Hashing (LSH)Spill-TreeNV TNV-TreeAll above run on a single machine with all data in memory, and scale to millions of images

Web-scale Approximate IndexingParallel variant of Spill-tree, NV-tree on distributed systems, Scale to Billions of images in disks on multiple machines

39© Eric Xing @ CMU, 2006-2011

Locality sensitive hashingApproximate kNN

Good enough in practiceg pCan get around curse of dimensionality

Locality sensitive hashingNear feature points (likely) same hash values

Hash table

40© Eric Xing @ CMU, 2006-2011

Page 21: “Nonparametric” “Nonparametric” methodsmethods

21

Example: Random projectionh(x) = sgn (x · r), r is a random unit vectorh(x) gives 1 bit Repeat and concatenateh(x) gives 1 bit. Repeat and concatenate. Prob[h(x) = h(y)] = 1 – θ(x,y) / π

r

yθ x

y

x

y

h(x) = 0, h(y) = 0 h(x) = 0, h(y) = 1x

h(x) = 0, h(y) = 1 hyperplane

Hash table000 101

x y

41© Eric Xing @ CMU, 2006-2011

Example: Random projectionh(x) = sgn (x · r), r is a random unit vectorh(x) gives 1 bit Repeat and concatenateh(x) gives 1 bit. Repeat and concatenate. Prob[h(x) = h(y)] = 1 – θ(x,y) / π

ry

θ

x

y

x

y

h(x) = 0, h(y) = 0 h(x) = 0, h(y) = 0x θ

h(x) = 0, h(y) = 0 hyperplane

Hash table000 101

x y

42© Eric Xing @ CMU, 2006-2011

Page 22: “Nonparametric” “Nonparametric” methodsmethods

22

Locality sensitive hashingRetrieved NNs

Hash table

?43© Eric Xing @ CMU, 2006-2011

Locality sensitive hashing

1000X speed-up with 50% recall of top 10-NN1.2M images + 1000 dimensions

0.5

0.6

0.7

1Pro

d at

top

10

L1Prod LSH + L1Prod rankingRandHP LSH + L1Prod ranking

exact N

N re

trieved

0.4 0.6 0.8 1 1.2 1.4 1.6x 10

−3

0.2

0.3

0.4

Rec

all o

f L1P

Scan cost

Percentage of points scanned

Percen

tage of 

44© Eric Xing @ CMU, 2006-2011

Page 23: “Nonparametric” “Nonparametric” methodsmethods

23

Summary: Nearest-Neighbor Learning Algorithm

Learning is just storing the representations of the training examples in D

Testing instance x:Compute similarity between x and all examples in D.Assign x the category of the most similar example in D.

Does not explicitly compute a generalization or category prototype

ffEfficient indexing needed in high dimensional, large-scale problems

Also called:Case-based learningMemory-based learningLazy learning

45© Eric Xing @ CMU, 2006-2011

Summary (continued)Bayes classifier is the best classifier which minimizes the probability of classification error.p yNonparametric and parametric classifierA nonparametric classifier does not rely on any assumption concerning the structure of the underlying density function.A classifier becomes the Bayes classifier if the density estimates converge to the true densities

when an infinite number of samples are usedpThe resulting error is the Bayes error, the smallest achievable error given the underlying distributions.

© Eric Xing @ CMU, 2006-2011

Page 24: “Nonparametric” “Nonparametric” methodsmethods

24

Clustering

47© Eric Xing @ CMU, 2006-2011

Data Clustering

Two different criteria Compactness, e.g., k-means, mixture modelsp , g , ,Connectivity, e.g., spectral clustering

Compactness Connectivity

48© Eric Xing @ CMU, 2006-2011

Page 25: “Nonparametric” “Nonparametric” methodsmethods

25

Graph-based ClusteringData Grouping

i

Image sigmentationAffinity matrix:

ijWG = {V,E}

Wij j

)),(( jiij xxdfW =

][wWAffinity matrix:Degree matrix:

][ , jiwW =)(diag idD =

49© Eric Xing @ CMU, 2006-2011

Affinity Function

2

2

2

ji XX

ji eW−−

=,

Affinities grow as σ grows

How the choice of σ value affects the results?

What would be the optimal choice for σ?

50© Eric Xing @ CMU, 2006-2011

Page 26: “Nonparametric” “Nonparametric” methodsmethods

26

Given a set of points S={s1,…sn}

A Spectral Clustering Algorithm Ng, Jordan, and Weiss 2003

2

2−− SS ji

Form the affinity matrix

Define diagonal matrix Dii= Σκ aik

Form the matrix

Stack the k largest eigenvectors of L to for the columns of the new matrix X:

02

2

=≠∀= iiji wjiew ,, , ,σ

2121 // −−= WDDL

⎤⎡ |||

Renormalize each of X’s rows to have unit length and get new matrix Y. Cluster rows of Y as points in R k

⎥⎥⎥

⎢⎢⎢

⎡=

|

|

|

|

|

|

kxxxX L21

51© Eric Xing @ CMU, 2006-2011

Why it works?

K-means in the spectrum space !

52© Eric Xing @ CMU, 2006-2011

Page 27: “Nonparametric” “Nonparametric” methodsmethods

27

More formally … Spectral clustering is equivalent to minimizing a generalized normalized cut

∑=

⎟⎟⎠

⎞⎜⎜⎝

⎛=

k

r A

rrk

rd

AAAAA1

21),(cut),Ncut(min K

YWDDY 2121 //Tmin −−

T

segments

pixeYIYY =T s.t.

elsY

53© Eric Xing @ CMU, 2006-2011

Wiji

j

Toy examples

Images from Matthew Brand (TR-2002-42)

54© Eric Xing @ CMU, 2006-2011

Page 28: “Nonparametric” “Nonparametric” methodsmethods

28

Spectral ClusteringAlgorithms that cluster points using eigenvectors of matrices derived from the data

Obtain data representation in the low-dimensional space that can be easily clustered

Variety of methods that use the eigenvectors differently (we have seen an example)

Empirically very successfulEmpirically very successful

Authors disagree:Which eigenvectors to useHow to derive clusters from these eigenvectors

55© Eric Xing @ CMU, 2006-2011

SummaryTwo nonparametric methods:

kNN classifier Spectrum clustering

A nonparametric method does not rely on any assumption concerning the structure of the underlying density function.

Good news:Simple and powerful methods; Flexible and easy to apply to many problems.kNN classifier asymptotically approaches the Bayes classifier, which is theoretically the best classifier that minimizes the probability of classification error.Spectrum clustering optimizes the normalized cut

Bad news:High memory requirementsVery dependant on the scale factor for a specific problem.

56© Eric Xing @ CMU, 2006-2011