clustering & association - university of notre damerjohns15/cse40647.sp14/www... · clustering...

25
Clustering & Association

Upload: others

Post on 03-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Clustering & Association

Page 2: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering - Overview

2

• What is cluster analysis? – Grouping data objects based only on information found in the data

describing these objects and their relationships – Maximize the similarity within objects in the same group – Maximize the difference between objects in different groups

Source: http://apandre.wordpress.com/visible-data/cluster-analysis/

Page 3: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering - Overview

3

• What is cluster analysis? – Similarity:

• Numerical measure of “alikeness” of two instances • Greater if more alike • Can be normalized to [0,1]

– Dissimilarity: • How different two instances are • Lower for “alike” instances

– These are usually expressed in terms of a distance function – Different weights can be assigned to different features – Hard to define what “similar enough” means. The answer is

typically highly subjective.

Page 4: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering - Overview

4

• What is cluster analysis? – Different from classification (supervised learning) in that the

labels for each instance are derived only from the data

– For that reason, cluster analysis is referred to as unsupervised classification

Page 5: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering - Overview

5

• Not well defined at times:

• How do we really know how many clusters should exist in the above example?

Page 6: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering - Overview

6

• Different types of clusterings: – Hierarchical versus Partitional

– Exclusive versus Overlapping versus Fuzzy

– Complete versus Partial

• Different types of clusters: – Well separated

– Prototype-Based

– Density-Based

– Shared-Property

Page 7: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering - Overview

7

(a) Well separated clusters (b) Center-based clusters

(c) Contiguity-based clusters (d) Density-based clusters (e) Conceptual clusters

Page 8: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

Clustering

8

1

2

3

K-means clustering

Hierarchical clustering

Evaluating clusters

Page 9: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering

9

• Works with numeric data only!

• Algorithm:

1. Pick a number k of random cluster centers

2. Assign every item to its nearest cluster center using a distance metric

3. Move each cluster center to the mean of its assigned items

4. Repeat 2-3 until convergence (change in cluster assignment less than a threshold)

Page 10: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

10

Y

X

Suppose we wish to cluster these items

Page 11: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

11

Y

X

Pick 3 initial cluster centers at random

𝑘1

𝑘2

𝑘3

Page 12: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

12

Y

X

Assign each instance to the closest cluster center

𝑘1

𝑘2

𝑘3

Page 13: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

13

Y

X

Move each cluster center to the mean of each cluster

𝑘1

𝑘2

𝑘3

Page 14: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

14

Y

X

Reassign points closest to a different new cluster center

𝑘3 𝑘2

𝑘1

Page 15: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

15

Y

X

Recompute cluster means

𝑘3 𝑘2

𝑘1

Page 16: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

16

Y

X

Reassign labels

No change. Done!

𝑘3

𝑘2

𝑘1

Page 17: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means clustering – Example

17

Y

X

Final clusters

Page 18: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means – Evaluating clusters

• If Euclidian distance is utilized as the proximity measure, the quality of clusters can be evaluated by the sum of squared error (SSE) – Calculate the distance between each point and its closest centroid (error)

– Sum the square of all errors

SSE = 𝑑𝑖𝑠𝑡 𝑐𝑖 , 𝑥2

𝑥∈𝐶𝑖

𝐾

𝑖=1

• It is important to choose values of k that minimize SSE

Page 19: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means – Discussion

• Results can vary significantly depending on initial choice of seeds

• How do you tackle this?

• How do you choose k?

Page 20: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

How do you choose k?

• Determining the number of clusters in a data set – The choice of k is often ambiguous and dependent on scale

and distribution of your dataset

– However, some generic methods for doing that do exist

• Rule of thumb: – 𝑘 ≈ 𝑛/2, where n is the number of instances

– This is a good starting point, but not a very reliable approach

Page 21: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

How do you choose k?

• The Elbow Method: – Choose a number of clusters that covers most of the variance

0%

20%

40%

60%

80%

100%

1 2 3 4 5 6 8 9

Per

cen

tage

of

vari

ance

exp

lain

ed

Number of clusters

Page 22: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

How do you choose k?

• Other methods: – Information Criterion Approach

– Silhouette method

– Jump method

– Gap statistic

Page 23: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means variations

• K-medoids – instead of mean, use medians of each cluster – Mean of 1, 3, 5, 7, 1009 is 205

– Median of 1, 3, 5, 7, 205 is 5

– Advantage: not affected by extreme values

• For large datasets, use sampling

Page 24: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

K-means pros and cons

• Pros: very efficient (even if multiple runs are performed), can be used for a large variety of data types.

• Cons: Not suitable for all types of data, susceptible to initialization problems and outliers, restricted to data in which there is a notion of a center

Page 25: Clustering & Association - University of Notre Damerjohns15/cse40647.sp14/www... · Clustering & Association K-means clustering 9 •Works with numeric data only! •Algorithm: 1

Data Preprocessing

Clustering & Association

And now…

Lets see some k-meaning!

25