cs 4900/5900: machine learning...

31
CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering and Computer Science [email protected] Clustering

Upload: others

Post on 27-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

CS 4900/5900: Machine Learning

Razvan C. Bunescu

School of Electrical Engineering and Computer Science

[email protected]

Clustering

Page 2: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Unsupervised Learning: Clustering

• Partition unlabeled examples into disjoint clusters such that:– Examples in the same cluster are very similar.– Examples in different clusters are very different.

2

Page 3: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Unsupervised Learning: Clustering

• Partition unlabeled examples into disjoint clusters such that:– Examples in the same cluster are very similar.– Examples in different clusters are very different.

3

Page 4: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Divisive Clustering with k-Means

• The goal is to produce k clusters such that instances are close to the cluster centroids:– The cluster centroid is the mean of all instances in the cluster.

• Optimization problem:

4

åå= Î

-=k

i Ci

i

CJ1

2||||)(x

mx

)(minargˆ CJCC

=

Page 5: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm

1. start with some seed centroids2. set t ¬ 0.3. while not converged:4. for each x: 5. set

6. set

7. set

8. set t ¬ t + 1

5

)0()0(2

)0(1 ,...,, kmmm

)()()(

minarg)( ti

tti

mxxmm

{ })()()1( )(| ti

ttiC mxmx =¬+

å+Î

++ ¬

)1()1(

)1( 1tiC

ti

ti C x

xm

[E] step

[M] step

Page 6: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

6

Pick seedsReassign clustersCompute centroids

xx

Reasssign clusters

xx xx Compute centroids

Reassign clusters

Converged!

Page 7: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

7

Page 8: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

8

Page 9: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

9

Page 10: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

10

Page 11: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

11

Page 12: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

12

Page 13: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

13

Page 14: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

14

Page 15: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm (k = 2)

15

Page 16: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm

• The objective function monotonically decreases at every iteration:

16

)1()( +³ tt JJ

[E] step

[M] step

Page 17: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm

• Optimization problem is NP-hard:– Results depend on seed selection.– Improve performance by providing must-link and/or cannot-link

constraints Þ semi-supervised clustering.

• Time complexity for each iteration is O(knm):– number of clusters is k.– feature vectors have dimensionality m.– total number of instances is n.

17

Page 18: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Means Algorithm

1. start with some seed centroids2. set t ¬ 0.3. while not converged:4. for each x: 5. set

6. set

7. set

8. set t ¬ t + 1

18

)0()0(2

)0(1 ,...,, kmmm

)()()(

minarg)( ti

tti

mxxmm

{ })()()1( )(| ti

ttiC mxmx =¬+

å+Î

++ ¬

)1()1(

)1( 1tiC

ti

ti C x

xm

[E] step

[M] step

Page 19: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The k-Medoids Algorithm

1. start with some random seed centroids2. set t ¬ 0.3. while not converged:4. for each x: 5. set

6. set

7. set

8. set t ¬ t + 1

19

)0()0(2

)0(1 ,...,, kmmm

m(t ) (x)← argminmi( t )d x−mi

(t )( ){ })()()1( )(| t

itt

iC mxmx =¬+

mi(t+1) ← arg min

x∈Ci( t+1)

d(x, y)y∈Ci

( t+1)∑

[E] step

[M] step

Page 20: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Soft Clustering

• Clustering typically assumes that each instance is given a “hard” assignment to exactly one cluster.

• Does not allow uncertainty in class membership or for an instance to belong to more than one cluster.

• Soft clustering gives probabilities that an instance belongs to each of a set of clusters.

• Each instance is assigned a probability distribution across a set of discovered categories.

20

Page 21: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Soft Clustering with EM

• Soft version of k-means.• Assumes a probabilistic model of categories that allows

computing P(ci | x) for each category, ci, for a given example x.– For text, typically assume a naïve-Bayes category model.

• Parameters q = {P(ci), P(wj | ci) | iÎ{1,…k}, j Î{1,…,|V|}}

21

Page 22: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Soft Clustering with EM

• Iterative method for learning probabilistic categorization model from unsupervised data.

• Initially assume random assignment of examples to categories.

• Learn an initial probabilistic model by estimating model parameters q from this randomly labeled data.

• Iterate following two steps until convergence:– Expectation (E-step): Compute P(ci | x) for each example given the

current model, and probabilistically re-label the examples based on these posterior probability estimates.

– Maximization (M-step): Re-estimate the model parameters, q, from the probabilistically re-labeled data.

22

Page 23: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Learning with Probabilistic Labels

• Instead of training data labeled with “hard” category labels, training data is labeled with “soft” probabilistic category labels.

• When estimating model parameters q from training data, weight counts by the corresponding probability of the given category label.

• For example, if P(c1 | x) = 0.8 and P(c2 | x) = 0.2, each word wj in x contributes only 0.8 towards the counts n1 and n1j, and 0.2 towards the counts n2 and n2j .

23

Page 24: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Naïve Bayes EM

24

1. Randomly assign examples probabilistic category labels.

2. Use standard naïve-Bayes training to learn a probabilistic

model with parameters q from the labeled data.

3. Until convergence or until maximum number of iterations

reached:• E-Step: Use the naïve Bayes model q to compute P(ci | x) for each

category and example, and re-label each example using these probability values as soft category labels.

• M-Step: Use standard naïve-Bayes training to re-estimate the parameters q using these new probabilistic category labels.

Page 25: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Hierarchical Agglomerative Clustering (HAC)

• Start out with n clusters, one example per cluster.• At each step merge the nearest two clusters.• Stop when there is only one cluster left, or:

– there are only k clusters left.– distance is above a threshold t.

• History of clustering decision can be represented as a binary tree.

25

Page 26: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

The HAC Algorithm

1. let Ci = {xi}, for iÎ1…n

2. let C = {Ci}, for iÎ1…n

3. while |C| > 1:

4. set

5. replace Ci , Cj in C with Ci È Cj

Q: How do we compute the distance d between two clusters?

26

),(minarg, lkCCji CCdCClk ¹

=ñá

Page 27: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Distance Measures

• Assume a distance function between any two instances:– Euclidean distance ||x-y||

• Single Link:

• Complete Link:

• Group Average:

• Centroid Distance:

27

yxyx

-=ÎÎ ji CCji CCd,min),(

yxyx

-=ÎÎ ji CCji CCd,max),(

åÎÎ

-*

=ji CCji

ji CCCCd

yxyx

,||||1),(

jiji CCd mm -=),(

Page 28: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Single Link (Nearest Neighbor)

• Distance function

• It favors elongated clusters.

• Equivalent with Kruskal’s MST algorithm.

28

yxyx

-=ÎÎ ji CCji CCd,min),(

Page 29: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Single Link

29

Page 30: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Complete Link (Farthest Neighbor)

• Distance function

• It favors tight, spherical clusters.

• d(Ci,Cj) is the diameter of the cluster Ci È Cj.

30

yxyx

-=ÎÎ ji CCji CCd,max),(

Page 31: CS 4900/5900: Machine Learning Clusteringoucsace.cs.ohio.edu/~razvan/courses/ml4900/lecture10.pdf · CS 4900/5900: Machine Learning Razvan C. Bunescu School of Electrical Engineering

Complete Link

31