08 clustering

84
สสสสสส สส.สสสสสสสสส สสสส สสสสสสสสสสส ภภภภภภภภภภภภภภภภภภภภภภภภภภภภภภภภภภภ ภภภภภภภภ ภภภภภ 8 : ภภภ ภภภภภภภภภภภภภภภ ภภภภภ (Clustering Analysis) 1

description

 

Transcript of 08 clustering

Page 1: 08 clustering

สอนโดย ดร.หทั�ยร�ตน เกต�มณี�ชั�ยร�ตน

ภาควิ�ชัาการจั�ดการเทัคโนโลย�การผล�ตและสารสนเทัศ

บทัทั�! 8 : การวิ�เคราะห การจั�ดกล�"ม

(Clustering Analysis)

1

Page 2: 08 clustering

What is Clustering in Data Mining?• Cluster : เป็�นกลุ่��มหรื�อคอเลุ่คชั�น (collection) ของวั�ตถุ�

– สามารืถุน�ามาจั�ดกลุ่��มก�นตามควัามเหม�อน (Similarity) – สามารืถุน�ามาจั�ดกลุ่��มก�นตามควัามแตกต�าง (Dissimilarity or Distance)

• Cluster Analysis– เป็�นกรืะบวันการืจั�ดวั�ตถุ�ต�างๆ ให!อยู่#�กลุ่��มที่%&เหมาะสม ซึ่(&งม%ค�ณสมบ�ต*ที่%&วั�ตถุ�ที่%&อยู่#�

ในกลุ่��มเด%ยู่วัก�นจัะคลุ่!ายู่ก�น แต�ม%ควัามแตกต�างจัากวั�ตถุ�ในกลุ่��มอ�&น• Clustering

– การืจั�ดกลุ่��มจัะแตกต�างจัากการืแบ�งป็รืะเภที่ข!อม#ลุ่ (Classification) โดยู่จัะแบ�งกลุ่��มข!อม#ลุ่จัากควัามคลุ่!ายู่ โดยู่ไม�ม%การืก�าหนดฉลุ่ากป็รืะเภที่ข!อม#ลุ่ไวั!ก�อนหรื�อเรืาไม�ที่รืาบจั�านวันกลุ่��มลุ่�วังหน!า เป็�นการืเรื%ยู่นรื# !แบบไม�ม%ผู้#!สอน (unsupervised classification)

2

Page 3: 08 clustering

Cluster Analysis

How many clusters?

Four Clusters Two Clusters

Six Clusters

3

Page 4: 08 clustering

What is Good Clustering?

• จั�ดกลุ่��มโดยู่พยู่ายู่ามให!ส*&งที่%&อยู่#�ในกลุ่��มเด%ยู่วัก�นม%ควัามคลุ่!ายู่คลุ่(งก�นมากที่%&ส�ด (Minimize Intra-Cluster Distances) แลุ่ะพยู่ายู่ามให!แต�ลุ่ะกลุ่��มม%ควัามแตกต�างก�นมากที่%&ส�ด (Maximize Inter-Cluster Distances)

Inter-cluster distances are maximized

Intra-cluster distances are

minimized

4

Page 5: 08 clustering

Types of Clustering

• Partitional Clustering– A division data objects into non-overlapping subsets

(clusters) such that each data object is in exactly one subset

Original Points A Partitional Clustering5

Page 6: 08 clustering

Types of Clustering

• Hierarchical clustering– A set of nested clusters organized as a hierarchical

tree

p4p1

p3

p2

p4 p1

p3

p2

p4p1 p2 p3

p4p1 p2 p3

Hierarchical Clustering#1

Hierarchical Clustering#2 Traditional Dendrogram 2

Traditional Dendrogram 1

6

Page 7: 08 clustering

Types of Clustering• Exclusive versus non-exclusive

– In non-exclusive clusterings, points may belong to multiple clusters.

– Can represent multiple classes or ‘border’ points

• Fuzzy versus non-fuzzy– In fuzzy clustering, a point belongs to every cluster with

some weight between 0 and 1– Weights must sum to 1– Probabilistic clustering has similar characteristics

• Partial versus complete– In some cases, we only want to cluster some of the data

• Heterogeneous versus homogeneous– Cluster of widely different sizes, shapes, and densities

7

Page 8: 08 clustering

Characteristics of Cluster• Well-Separated Clusters:

– A cluster is a set of points such that any point in a cluster is closer (or more similar) to every other point in the cluster than to any point not in the cluster.

3 well-separated clusters

8

Page 9: 08 clustering

Characteristics of Cluster

• Center-based– A cluster is a set of objects such that an object in a

cluster is closer (more similar) to the “center” of a cluster, than to the center of any other cluster.

– The center of a cluster is often a centroid, the average of all the points in the cluster, or a medoid, the most “representative” point of a cluster.

4 center-based clusters

9

Page 10: 08 clustering

Characteristics of Cluster• Density-based

– A cluster is a dense region of points, which is separated by low-density regions, from other regions of high density.

– Used when the clusters are irregular, and when noise and outliers are present.

6 density-based clusters

10

Page 11: 08 clustering

Characteristics of Cluster• Shared Property or Conceptual

Clusters– Finds clusters that share some common

property or represent a particular concept.

2 Overlapping Circles

11

Page 12: 08 clustering

Clustering Algorithms

• K-means clustering

• Hierarchical clustering

12

Page 13: 08 clustering

K-means Clustering• ใชั!หลุ่�กการืการืต�ดแบ�ง (Partition) แบ�งวั�ตถุ� n ต�วัในฐาน

ข!อม#ลุ่ D ออกเป็�นจั�านวัน k กลุ่��ม (สมมต*วั�าเรืาที่รืาบค�า k) • อ�ลุ่กอรื*ที่(ม k-Means จัะต�ดแบ�งวั�ตถุ�ออกเป็�น k กลุ่��ม โดยู่

การืแที่นแต�ลุ่ะกลุ่��มด!วัยู่ค�าเฉลุ่%&ยู่ของกลุ่��ม ซึ่(&งใชั!เป็�นจั�ดศู#นยู่3กลุ่างของกลุ่��มในการืวั�ดรืะยู่ะห�างของต�วัอยู่�างในกลุ่��มเด%ยู่วัก�น

13

Page 14: 08 clustering

K-means Clustering Algorithm

Algorithm: The k-Means algorithm for partitioning based on the mean value of object in the cluster.

Input: The number of cluster k and a database containing n objects.

Output: A set of k clusters that mininimizes the squared-error criterion.

14

Page 15: 08 clustering

K-means Clustering Algorithm

Method1) Randomly choose k object as the initial cluster

centers (centroid);2) Repeat3) (re)assign each object to the cluster to which the

object is the most similar, based on the mean value of the objects in the cluster;

4) Update the cluster mean calculate the mean value of the objects for each

cluster;5) Until centroid (center point) no change;

15

Page 16: 08 clustering

Example: K-Mean Clustering• Problem: Cluster the following eight points

(with (x, y) representing locations) into three clusters A1(2, 10) A2(2, 5) A3(8, 4) A4(5, 8) A5(7, 5) A6(6, 4) A7(1, 2) A8(4, 9).

0 1 2 3 4 5 6 7 8 90

2

4

6

8

10

12

16

Page 17: 08 clustering

Example: K-Mean Clustering• Randomly choose k object as the initial cluster

centers; • k =3 ; c1(2, 10), c2(5, 8) and c3(1, 2).

0 1 2 3 4 5 6 7 8 90

2

4

6

8

10

12

+

+

+

c1

c2

c3

17

Page 18: 08 clustering

Example: K-Mean Clustering

• The distance function between two points a=(x1, y1) and b=(x2, y2) is defined as:

distance(a, b) = |x2 – x1| + |y2 – y1| (2, 10) (5, 8) (1, 2)

Point Dist Mean 1 Dist Mean 2 Dist Mean 3 Cluster

A1 (2, 10)

A2 (2, 5)

A3 (8, 4)

A4 (5, 8)

A5 (7, 5)

A6 (6, 4)

A7 (1, 2)

A8 (4, 9)

18

Page 19: 08 clustering

Example: K-Mean Clustering• Step 2 Calculate distance by using the

distance functionpoint mean1x1, y1 x2, y2(2, 10) (2, 10) distance(point, mean1) = |x2 – x1| + |y2 – y1|

= |2 – 2| + |10 – 10| = 0 + 0 = 0

point mean2x1, y1 x2, y2(2, 10) (5, 8) distance(point, mean2) = |x2 – x1| + |y2 – y1|

= |5 – 2| + |8 – 10| = 3 + 2 = 5point mean3x1, y1 x2, y2(2, 10) (1, 2) distance(point, mean3) = |x2 – x1| + |y2 – y1|

= |1 – 2| + |2 – 10| = 1 + 8 = 9

19

Page 20: 08 clustering

Example: K-Mean Clustering

(2, 10) (5, 8) (1, 2)

Point Dist Mean 1 Dist Mean 2 Dist Mean 3 Cluster

A1 (2, 10) 0 5 9 1

A2 (2, 5)

A3 (8, 4)

A4 (5, 8)

A5 (7, 5)

A6 (6, 4)

A7 (1, 2)

A8 (4, 9)

20

Page 21: 08 clustering

Example: K-Mean Clustering• Calculate distance by using the distance

functionpoint mean1x1, y1 x2, y2(2, 5) (2, 10) distance(point, mean1) = |x2 – x1| + |y2 – y1|

= |2 – 2| + |10 – 5| = 0 + 5 = 5

point mean2x1, y1 x2, y2(2, 5) (5, 8) distance(point, mean2) = |x2 – x1| + |y2 – y1|

= |5 – 2| + |8 – 5| = 3 + 3 = 6

point mean3x1, y1 x2, y2(2, 5) (1, 2) distance(point, mean3) = |x2 – x1| + |y2 – y1|

= |1 – 2| + |2 – 5| = 1 + 3 = 4

21

Page 22: 08 clustering

Example: K-Mean Clustering

(2, 10) (5, 8) (1, 2)

Point Dist Mean 1 Dist Mean 2 Dist Mean 3 Cluster

A1 (2, 10) 0 5 9 1

A2 (2, 5) 5 6 4 3

A3 (8, 4)

A4 (5, 8)

A5 (7, 5)

A6 (6, 4)

A7 (1, 2)

A8 (4, 9)

22

Page 23: 08 clustering

Example: K-Mean Clustering• Iteration#1

(2, 10) (5, 8) (1, 2)

Point Dist Mean 1 Dist Mean 2 Dist Mean 3 Cluster

A1 (2, 10) 0 5 9 1

A2 (2, 5) 5 6 4 3

A3 (8, 4) 12 7 9 2

A4 (5, 8) 5 0 10 2

A5 (7, 5) 10 5 9 2

A6 (6, 4) 10 5 7 2

A7 (1, 2) 9 10 0 3

A8 (4, 9) 3 2 10 2

23

Page 24: 08 clustering

Example: K-Mean ClusteringCluster 1 Cluster 2 Cluster 3A1(2, 10) A3(8, 4) A2(2, 5)

A4(5, 8) A7(1, 2)A5(7, 5)A6(6, 4)A8(4, 9)

0 1 2 3 4 5 6 7 8 90

2

4

6

8

10

12

+

+

c1

c2

c3+

24

Page 25: 08 clustering

Example: K-Mean Clustering

• re-compute the new cluster centers (means). We do so, by taking the mean of all points in each cluster.

• For Cluster 1, we only have one point A1(2, 10), which was the old mean, so the cluster center remains the same.

• For Cluster 2, we have ( (8+5+7+6+4)/5, (4+8+5+4+9)/5 ) = (6, 6)

• For Cluster 3, we have ( (2+1)/2, (5+2)/2 ) = (1.5, 3.5)

25

Page 26: 08 clustering

Example: K-Mean Clustering

0 1 2 3 4 5 6 7 8 90

2

4

6

8

10

12

+

+

c1

c2

c3+

26

Page 27: 08 clustering

Example: K-Mean Clustering

• Iteration#2

(2, 10) (6, 6) (1.5, 3.5)

Point Dist Mean 1 Dist Mean 2 Dist Mean 3 Cluster

A1 (2, 10)

A2 (2, 5)

A3 (8, 4)

A4 (5, 8)

A5 (7, 5)

A6 (6, 4)

A7 (1, 2)

A8 (4, 9)

27

Page 28: 08 clustering

Example: K-Mean Clustering (Iteration#2)

Cluster 1? Cluster 2? Cluster 3?

0 1 2 3 4 5 6 7 8 90

2

4

6

8

10

12

re-compute the new cluster centers (means)C1 = (2+4/2, 10+9/2) = (3, 9.5)C2 = (6.5, 5.25)C3 = (1.5, 3.5)

28

Page 29: 08 clustering

Example: K-Mean ClusteringIteration#3Cluster 1? Cluster 2? Cluster 3?

0 1 2 3 4 5 6 7 8 90

2

4

6

8

10

12

re-compute the new cluster centers (means)??

29

Page 30: 08 clustering

Distance functions

• ฟั5งก3ชั�นรืะยู่ะห�างที่%&วั�ดควัามไม�คลุ่!ายู่รืะหวั�างวั�ตถุ� 2 ต�วั ซึ่(&งน*ยู่มใชั!ก�นอยู่�างแพรื�หลุ่ายู่

• Minkowski distance

• ถุ!า q=1 เรืาเรื%ยู่ก d วั�า Manhattan distance

• ถุ!า q=2 เรืาเรื%ยู่ก d วั�า Euclidean distance

q q

jpip

q

ji

q

ji xxxxxxjid )...(),( 2211

jpipjiji xxxxxxjid ...),( 2211

)...(),(22

22

2

11 jpipjiji xxxxxxjid

30

Page 31: 08 clustering

Evaluating K-means Clusters• Most common measure is Sum of

Squared Error (SSE)– For each point, the error is the

distance to the nearest cluster– To get SSE, we square these errors

and sum them.

where,– x is a data point in cluster Ci

–mi is the centroid point for cluster Ci • can show that mi corresponds to

the center (mean) of the cluster

K

i Cxi

i

xmdistSSE1

2 ),(

31

Page 32: 08 clustering

Limitations of K-Mean

• K-means ม%ข!อจั�าก�ดในการืหากลุ่��ม ด�งน%6–Size–Density–Shapes

32

Page 33: 08 clustering

Limitations of K-means: Differing Sizes• K-means ไม�สามารืถุจั�ดเป็�น 3 กลุ่��มได! เพรืาะวั�าหน(&งกลุ่��มใน

น�6นม%ขนาดใหญ่�กวั�าสองกลุ่��มที่%&เหลุ่�อมาก แลุ่ะในขณะน%6กลุ่��มที่%&ใหญ่�กวั�าถุ#กที่�าการืแตก หน(&งกลุ่��มที่%&เลุ่8กกวั�าจัะถุ#กรืวัมเข!าก�บส�วันของกลุ่��มที่%&ใหญ่�กวั�า

Original Points K-means (3 Clusters)

33

Page 34: 08 clustering

Limitations of K-means: Differing Density• K-means จัะลุ่!มเหลุ่วัในการืหากลุ่��ม 3 กลุ่��ม เพรืาะวั�า 2 กลุ่��มที่%&

เลุ่8กกวั�าจัะม%ควัามหนาแน�นมากกวั�ากลุ่��มที่%&ใหญ่�กวั�า

Original Points K-means (3 Clusters)

34

Page 35: 08 clustering

Limitations of K-means: Non-globular Shapes• K-means หากลุ่��ม 2 กลุ่��มที่%&ม%ส�วันที่%&ผู้สมก�น เพรืาะรื#ป็รื�างเด*ม

ของกลุ่��มไม�เป็�นรื#ป็ที่รืงกลุ่ม

Original Points K-means (2 Clusters)

35

Page 36: 08 clustering

Overcoming K-means Limitations

Original Points K-means Clusters

One solution is to use many clusters.

Find parts of clusters, but need to put together.

36

Page 37: 08 clustering

Overcoming K-means Limitations

Original Points K-means Clusters

Page 38: 08 clustering

Overcoming K-means Limitations

Original Points K-means Clusters

38

Page 39: 08 clustering

Hierarchical Clustering

• เป็�นการืจั�บกลุ่��มที่%&ม%ลุ่�กษณะเป็�นไป็ตามลุ่�าด�บชั�6น ส�วันใหญ่�จัะแสดงในรื#ป็แบบของกรืาฟัแผู้นภาพที่%&ม%ลุ่�กษณะคลุ่!ายู่ต!นไม! เรื%ยู่กวั�า Dendrogram

• Dendrogram แสดงให!เห8นถุ(งควัามส�มพ�นธ์3ของกลุ่��ม (cluster) ก�บกลุ่��มยู่�อยู่ๆ (subcluster) แลุ่ะลุ่�าด�บของกลุ่��ม (cluster) ที่%&ถุ#กรืวัมเป็�นกลุ่��มเด%ยู่วัก�น หรื�อถุ#กแบ�งแยู่ก

1 3 2 5 4 60

0.05

0.1

0.15

0.2

1

2

3

4

5

6

1

23 4

5

Dendrogram

39

Page 40: 08 clustering

Hierarchical Clustering

ม%วั*ธ์%การืพ�6นฐานอยู่#� 2 วั*ธ์%การื ด�งน%61. Agglomerative (รืวัมเป็�นกลุ่��มเป็�นก!อน) :

วั*ธ์%การื Agglomerative เรื*&มต!นจัากพ*จัารืณาจั�ดหรื�อต�าแหน�งที่%&อยู่#�ในบรื*เวัณส�วันเฉพาะของแต�ลุ่ะกลุ่��ม ซึ่(&งแต�ลุ่ะข�6นตอนจัะที่�าการืรืวัมกลุ่��มเข!าด!วัยู่ก�นโดยู่การืพ*จัารืณากลุ่��มค#�ที่%&ใกลุ่!ก�นมากที่%&ส�ด แนวัค*ดของวั*ธ์%การืน%6เพ�&อก�าหนดควัามใกลุ่!ชั*ดหรื�อควัามส�มพ�นธ์3ของกลุ่��มน�6นๆ รืวัมเข!าด!วัยู่ก�น

2. Divisive (แบ�งแยู่กแตกออก) : วั*ธ์%การื Divisive เรื*&มต!นเชั�นเด%ยู่วัก�บวั*ธ์%การื Agglomerative ที่�าก�บที่�6งหมดที่�กๆ

กลุ่��ม ซึ่(&งแต�ลุ่ะข�6นตอนจัะที่�าการืแบ�งแยู่กออก จันกรืะที่�&งเหลุ่�อเพ%ยู่งกลุ่��มที่%&ม%ลุ่�กษณะม%เพ%ยู่งส*&งเด%ยู่วั (singleton cluster) ในกรืณ%น%6เรืาต!องต�ดส*นใจัได!วั�ากลุ่��มไหนหรื�อ cluster ไหนที่%&ควัรืแบ�งแยู่ก แลุ่ะจัะที่�าการืแบ�งแยู่กอยู่�างไรื

40

Page 41: 08 clustering

Agglomerative Clustering Algorithm

Basic algorithm is straightforward1. Compute the proximity matrix2. Let each data point be a cluster3. Repeat4. Merge the two closest clusters5. Update the proximity matrix6. Until only a single cluster remains

41

Page 42: 08 clustering

Example:

42

Page 43: 08 clustering

Example:

43

Page 44: 08 clustering

Example:

ตาราง แสดงรืะยู่ะห�างรืะหวั�างจั�ดน�6นๆ ที่�6ง 6 จั�ด ด!วัยู่วั*ธ์%การื Euclidean distance

44

Page 45: 08 clustering

How to Define Inter-Cluster Similarity

p1

p3

p5

p4

p2

p1 p2 p3 p4 p5 . . .

.

.

.

Similarity?

Proximity Matrix

MIN MAX Group Average Ward’s Method uses squared

error

45

Page 46: 08 clustering

How to Define Inter-Cluster Similarity

MIN MAX Group Average Ward’s Method uses squared

error

p1

p3

p5

p4

p2

p1 p2 p3 p4 p5 . . .

.

.

.Proximity Matrix

46

Page 47: 08 clustering

How to Define Inter-Cluster Similarity

p1

p3

p5

p4

p2

p1 p2 p3 p4 p5 . . .

.

.

.Proximity Matrix

MIN MAX Group Average Ward’s Method uses squared error

47

Page 48: 08 clustering

How to Define Inter-Cluster Similarity

p1

p3

p5

p4

p2

p1 p2 p3 p4 p5 . . .

.

.

.Proximity Matrix

MIN MAX Group Average Ward’s Method uses squared error

48

Page 49: 08 clustering

Cluster Similarity: MIN or Single Link

• วั*ธ์%การื Single link หรื�อ MIN ของการืจั�ดกลุ่��ม Hierarchical Clustering โดยู่ควัามส�มพ�นธ์3ที่�6งสองกลุ่��มที่%&ก�าหนดน�6นม%รืะยู่ะห�างรืะหวั�างจั�ด 2 จั�ดที่%&อยู่#�ต�างกลุ่��มก�นน!อยู่ที่%&ส�ด

49

Page 50: 08 clustering

Cluster Similarity: MIN or Single Link

1

2

3

4

5

6

1

3 6 2 5 4 10

0.05

0.1

0.15

0.2

0.11

50

Page 51: 08 clustering

Cluster Similarity: MIN or Single Link

1

2

3

4

5

6

1

3 6 2 5 4 10

0.05

0.1

0.15

0.2

Dist({3,6},{2}) = min(dist(3,2), dist(6,2)) min(0.15, 0.25) = 0.15Dist({3,6}, {5}) = min(dist(3,5), dist(6,5)) =0.28Dist ({3,6}, {4}) = min(dist(3,4), dist(6,4)) = 0.15Dist({3,6}, {1}) = min(dist(3,1), dist(6,1)) = 0.22

51

Page 52: 08 clustering

Cluster Similarity: MIN or Single Link

1

2

3

4

5

6

12

3 6 2 5 4 10

0.05

0.1

0.15

0.2

Dist({3,6},{2}) = min(dist(3,2), dist(6,2)) min(0.15, 0.25) = 0.15Dist ({3,6}, {4}) = min(dist(3,4), dist(6,4)) = 0.15

Dist ({3,6},{2}), Dist ({3,6}, {4}) > dist(5,2) = 0.14

0.14

52

Page 53: 08 clustering

Cluster Similarity: MIN or Single Link

1

2

3

4

5

6

12

3

3 6 2 5 4 10

0.05

0.1

0.15

0.2

Dist({3,6},{2,5}) = min(dist(3,2), dist(6,2), dist(3,5), dist(6,5)) = min(0.15, 0.25, 0.28, 0.39)

=0.15Dist ({3,6},{1}) = min(dist(3,1), dist(6,1)) = min(0.22, 0.23) = 0.22Dist ({3,6},{4}) = min (dist(3,4), dist(6,4))

= min(0.15, 0.22) = 0.15

53

Page 54: 08 clustering

Cluster Similarity: MIN or Single Link

1

2

3

4

5

6

12

3

43 6 2 5 4 1

0

0.05

0.1

0.15

0.2

Dist({3,6,2,5}, {1}) = min(dist(3,1), dist(6,1), dist(2,1), dist(5,1)) = min(0.22, 0.23, 0.24, 0.34) = 0.22

Dist(({3,6,2,5}, {4}) = min(dist(3,4), dist(6,4), dist(2,4), dist(5,4)) = min(0.15, 0.22, 0.20, 0.29) = 0.15

Page 55: 08 clustering

Cluster Similarity: MIN or Single Link

1

2

3

4

5

6

12

3

4

5

3 6 2 5 4 10

0.05

0.1

0.15

0.2

Dist(({3,6,2,5,4}, {1}) = min(dist(3,1), dist(6,1), dist(2,1), dist(5,1), dist(4,1)) = min(0.22, 0.23, 0.24, 0.34, 0.37)

= 0.22

55

Page 56: 08 clustering

Strength of MIN

Original Points Two Clusters

• Can handle non-elliptical shapes

56

Page 57: 08 clustering

Limitations of MIN

• แ

Original Points Two Clusters

• Sensitive to noise and outliers

57

Page 58: 08 clustering

Cluster Similarity: MAX or Complete Linkage

• วั*ธ์%การื Complete link หรื�อ MAX ของการืจั�ดกลุ่��ม Hierarchical Clustering โดยู่ควัามส�มพ�นธ์3ที่�6งสองกลุ่��มที่%&ก�าหนดน�6นม%รืะยู่ะห�างรืะหวั�างจั�ด 2 จั�ดที่%&อยู่#�ต�างกลุ่��มก�นมากที่%&ส�ด

58

Page 59: 08 clustering

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

Cluster Similarity: MAX or Complete Linkage

1

2

3

4

5

6

10.11

59

Page 60: 08 clustering

Cluster Similarity: MAX or Complete Linkage

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

1

2

3

4

5

6

1

Dist({3,6},{1}) = max(dist(3,1), dist(6,1))= 0.23

Dist({3,6},{2}) = max(dist(3,2), dist(6,2))= 0.25

Dist({3,6},{4}) = max(dist(3,4), dist(6,4))= 0.22**

Dist({3,6},{5}) = max(dist(3,5), dist(6,5))= 0.3960

Page 61: 08 clustering

Cluster Similarity: MAX or Complete Linkage

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

1

2

3

4

5

6

1

2

Dist({3,6},{4}) = max(dist(3,4), dist(6,4))= 0.22 > Dist({2},{5})

0.14

61

Page 62: 08 clustering

Cluster Similarity: MAX or Complete Linkage

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

1

2

3

4

5

6

13

Dist({3,6},{1}) = max(dist(3,1), dist(6,1))= 0.23Dist({3,6},{2,5}) = max(dist(3,2), dist(3,5), dist(6,2), dist(6,5))

= 0.39Dist({3,6},{4}) = max(dist(3,4), dist(6,4))= 0.22**Dist({2,5},{4}) = max(dist(2,4), dist(5,4)) = 0.29Dist({2,5}, {1}) = max(dist(2,1), dist(5,1)) = 0.34

0.22

2

62

Page 63: 08 clustering

Cluster Similarity: MAX or Complete Linkage

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

1

2

3

4

5

6

1

2

3

4

Dist({2,5}, {1}) = max(dist(2,1), dist(5,1))= 0.34**

Dist({2,5}, {3,6,4}) = max(dist(2,3), dist(2,6), dist(2,4)),dist(5,3), dist(5,6), dist(5,4))

= max(0.15, 0.25, 0.20, 0.28, 0.39, 0.29) = 0.39

0.34

63

Page 64: 08 clustering

Cluster Similarity: MAX or Complete Linkage

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

1

2

3

4

5

6

1

3 5

2

4

Dist({2,5,1},{3,6,4}) = max(dist(2,3), dist(2,6), dist(2,4) dist(5,3), dist(5, 6), dist(5,4) dist(1,3), dist(1,6), dist(1,4))= max(0.15, 0.25, 0.20, 0.28, 0.39, 0.29, 0.22, 0.23,0.37)=0.39

0.39

64

Page 65: 08 clustering

Strength of MAX

Original Points Two Clusters

• Less susceptible to noise and outliers

65

Page 66: 08 clustering

Limitations of MAX

Original Points Two Clusters

• Tends to break large clusters

• Biased towards globular clusters

66

Page 67: 08 clustering

Cluster Similarity: Group Average

• วั*ธ์%การื Group average ของการืจั�ดกลุ่��ม Hierarchical Clustering โดยู่ควัามส�มพ�นธ์3ที่�6งสองกลุ่��มที่%&ก�าหนดน�6น ค�าเฉลุ่%&ยู่ของที่�ก ๆ ค#�ของจั�ดที่%&อยู่#�ต�างกลุ่��มก�น วั*ธ์%การืน%6เป็�นต�วักลุ่างรืะหวั�างวั*ธ์%การื Single link แลุ่ะวั*ธ์%การื compete link

67

Page 68: 08 clustering

Cluster Similarity: Group Average Linkage

1

2

3

4

5

6

1

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

2 5 1

0.11

68

Page 69: 08 clustering

Cluster Similarity: Group Average

1

2

3

4

5

6

1

Dist({3,6},{1}) = avg(dist(3,1), dist(6,1)) = (0.22+0.23)/(2*1) = 0.225

Dist ({3,6},{2}) = avg(dist(3,2), dist(6,2)) = (0.15+0.25)/(2*1) = 0.20

Dist({3,6},{4}) = avg(dist(3,4), dist(6,4)) = (0.15+0.22)/(2*1) = 0.185**

Dist({3,6}, {5}) = avg(dist(3,5), dist(6,5)) = (0.28+0.39)/(2*1) = 0.335

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

2 5 1

0.11

69

Page 70: 08 clustering

Cluster Similarity: Group Average

1

2

3

4

5

6

1

2

Dist({3,6},{4}) = avg(dist(3,4), dist(6,4)) = (0.15+0.22)/(2*1) = 0.185** > Dist({2}, {5})

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

2 5 1

0.14

70

Page 71: 08 clustering

Cluster Similarity: Group Average

1

2

3

4

5

6

1

2

33 6 4 1 2 5

0

0.05

0.1

0.15

0.2

0.25

2 5 1

Dist({3,6},{1}) = avg(dist(3,1), dist(6,1)) = (0.22+0.23)/(2*1) = 0.225

Dist ({3,6},{2}) = avg(dist(3,2), dist(6,2)) = (0.15+0.25)/(2*1) = 0.20

Dist({3,6},{4}) = avg(dist(3,4), dist(6,4)) = (0.15+0.22)/(2*1) = 0.185**

Dist({3,6}, {5}) = avg(dist(3,5), dist(6,5)) = (0.28+0.39)/(2*1) = 0.335

0.185

71

Page 72: 08 clustering

Cluster Similarity: Group Average

1

2

3

4

5

6

1

2

33 6 4 1 2 5

0

0.05

0.1

0.15

0.2

0.25

2 5 1

Dist({3,6, 4},{1}) = avg(dist(3,1), dist(6,1), dist(4,1)) = (0.22+0.23+0.37)/(3*1) = 0.273

Dist ({3,6,4},{2,5}) = avg(dist(3,2), dist(3,5), dist(6,2), dist(6,5), dist(4,2), dist(4,5))

= (0.15+0.28+0.25+0.39+0.20+0.29)/(3*2) = 0.26

4

0.26

Page 73: 08 clustering

Cluster Similarity: Group Average

1

2

3

4

5

6

1

2

5

33 6 4 1 2 5

0

0.05

0.1

0.15

0.2

0.25

2 5 1

4

Dist ({3,6,4,2,5}, {1}) = avg(dist(3,1), dist(6,1), dist(4,1), dist(2,1),dist(5,1)) = (0.22+0.23+0.37+0.24+0.34)/(5*1) = 0.28

0.28

73

Page 74: 08 clustering

Hierarchical Clustering: Group Average

• Compromise between Single and Complete Link

• Strengths– Less susceptible to noise and outliers

• Limitations– Biased towards globular clusters

74

Page 75: 08 clustering

Hierarchical Clustering: Comparison

Group Average

MIN MAX

1

2

3

4

5

61

2

5

34

1

2

3

4

5

61

2 5

3

41

2

3

4

5

6

12

3

4

5

75

Page 76: 08 clustering

Hierarchical Clustering: Comparison

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

2 5 1

Group Average

3 6 4 1 2 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

MAX

3 6 2 5 4 10

0.05

0.1

0.15

0.2

MIN

76

Page 77: 08 clustering

Internal Measures : Cohesion and Separation

(graph-based clusters)• A graph-based cluster approach can be evaluated by cohesion and separation measures.– Cluster cohesion is the sum of the weight of all links within

a cluster.– Cluster separation is the sum of the weights between

nodes in the cluster and nodes outside the cluster.

cohesion separation

77

Page 78: 08 clustering

Cohesion and Separation (Central-based clusters)

• A central-based cluster approach can be evaluated by cohesion and separation measures.

78

Page 79: 08 clustering

Cohesion and Separation (Central-based clustering)

• Cluster Cohesion: Measures how closely related are objects in a cluster– Cohesion is measured by the within cluster sum of

squares (SSE)

• Cluster Separation: Measure how distinct or well-separated a cluster is from other clusters– Separation is measured by the between cluster sum of

squares

»Where |Ci| is the size of cluster i

i Cx

i

i

mxWSS 2)(

i

ii mmCBSS 2)(

79

Page 80: 08 clustering

Example: Cohesion and Separation

Example: WSS + BSS = Total SSE (constant)

1 2 3 4 5m

1091

9)5.43(2)5.13(2

1)5.45()5.44()5.12()5.11(22

2222

Total

BSS

WSSK=2 clusters:

10010

0)33(4

10)35()34()32()31(2

2222

Total

BSS

WSSK=1 cluster:

1 2 3 4 5 m1 m2

m

Page 81: 08 clustering

81

HW#8

• ให!ที่�า Database Segmentation ด!วัยู่วั*ธ์%การืแบบK-means clustering โดยู่ก�าหนดให! K=3 แลุ่ะ

จั�ดศู#นยู่3กลุ่างเรื*&มต!นของที่�6งสามกลุ่��มค�อ C1 = (1,5) , C2 = (3,12) แลุ่ะ C3 = (2,13) โดยู่ม%ข!อม#ลุ่ที่%&

เข!าส#�โมเดลุ่ 10 ชั�ด (Pattern) ด�งตารืางด!านลุ่�าง ให!น�กศู(กษาค�านวัณหาค�าการืจั�ดกลุ่��มตามอ�ลุ่กอรื*ที่(ม

ของ K-means โดยู่ที่�า 2 รือบ

Page 82: 08 clustering

82

HW#8

• What is cluster?• What is Good Clustering?• How many types of clustering?• How many Characteristics of Cluster?• What is K-means Clustering?• What are limitations of K-Mean?• Please explain method of Hierarchical

Clustering?

Page 83: 08 clustering

ID X Y

A1 1 5

A2 4 9

A3 8 15

A4 6 2

A5 3 12

A6 10 7

A7 7 7

A8 11 4

A9 13 10A10 2 13

Page 84: 08 clustering

84

LAB 8

• Use weka program to construct a neural network classification from the given file.

• Weka Explorer Open file bank.arff • Cluster Choose button

SimpleKMeans Next, click on the text box to the right of the "Choose" button to get the pop-up window