0% found this document useful (0 votes)
47 views80 pages

Lect 12

The document discusses clustering, an unsupervised machine learning technique used to group unlabeled data points into clusters. It defines clustering and describes its goal of maximizing similarity within clusters and minimizing similarity between clusters. Various types of clustering are covered, including partitional, hierarchical, density-based, and those defined by an objective function. Applications of clustering and factors that affect determining proximity and density between data points are also summarized.

Uploaded by

Abdul Hannan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views80 pages

Lect 12

The document discusses clustering, an unsupervised machine learning technique used to group unlabeled data points into clusters. It defines clustering and describes its goal of maximizing similarity within clusters and minimizing similarity between clusters. Various types of clustering are covered, including partitional, hierarchical, density-based, and those defined by an objective function. Applications of clustering and factors that affect determining proximity and density between data points are also summarized.

Uploaded by

Abdul Hannan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

1

Data Mining

Clustering

Lecture # 12
Important Announcements

 Semester Project will be uploaded on LMS (16-05-2023)


– Report Submission deadline is 08-June-2023 (.pdf)
– Project Presentation will be on 08-June-2023 (.ppt)
– Project to be done in group. (3 members max)
Group member names to be emailed before 15-June-2023)
[email protected]

 Assignment 2 will be uploaded on 19-05-2023


– Submission deadline: 29-05-2023

 Quiz to be conducted at the end of every class.


– Next quiz topic “Clustering”

 Assessment marks uploaded on Qalam


What is Clustering ?

 Clustering:
Process of grouping a set of objects into classes
of similar object.

 The commonest form of unsupervised learning


Unsupervised learning = learning from raw data, as
opposed to supervised data where a classification of
examples is given
– A common and important task that finds many
applications in IR and DM task.
What is Cluster Analysis?

 Given a set of objects, place them in groups such that the


objects in a group are similar (or related) to one another and
different from (or unrelated to) the objects in other groups

Inter-cluster
Intra-cluster distances are
distances are maximized
minimized
Goal of Clustering

 Given a set of data points, each described by a


set of attributes, find clusters such that:

– Inter-cluster similarity is F1 xx
xx
x xx x
maximized xx
xxxx
x
xxx
– Intra-cluster similarity is x
minimized
F2

 Requires the definition of a similarity measure


Defining Distance Measure

 Definition: Let O1 and O2 be two objects from the


universe of possible objects. The distance (dissimilarity)
between O1 and O2 is a real number denoted by D(O1,O2)

Peter Piotr

0.23 3 342.7
Applications of Cluster Analysis
Discovered Clusters Industry Group
 Understanding Applied-Matl-DOWN,Bay-Network-Down,3-COM-DOWN,

– Group related documents 1 Cabletron-Sys-DOWN,CISCO-DOWN,HP-DOWN,


DSC-Comm-DOWN,INTEL-DOWN,LSI-Logic-DOWN,
Micron-Tech-DOWN,Texas-Inst-Down,Tellabs-Inc-Down,
Technology1-DOWN
Natl-Semiconduct-DOWN,Oracl-DOWN,SGI-DOWN,
for browsing, Sun-DOWN
Apple-Comp-DOWN,Autodesk-DOWN,DEC-DOWN,

– group genes and proteins 2 ADV-Micro-Device-DOWN,Andrew-Corp-DOWN,


Computer-Assoc-DOWN,Circuit-City-DOWN,
Compaq-DOWN, EMC-Corp-DOWN, Gen-Inst-DOWN,
Technology2-DOWN
Motorola-DOWN,Microsoft-DOWN,Scientific-Atl-DOWN
that have similar Fannie-Mae-DOWN,Fed-Home-Loan-DOWN,

functionality, 3 MBNA-Corp-DOWN,Morgan-Stanley-DOWN Financial-DOWN


Baker-Hughes-UP,Dresser-Inds-UP,Halliburton-HLD-UP,

– or group stocks with similar 4 Louisiana-Land-UP,Phillips-Petro-UP,Unocal-UP,


Schlumberger-UP
Oil-UP

price fluctuations

 Summarization
– Reduce the size of large
data sets
Clustering precipitation
in Australia
Application of Clustering

 Marketing: Help marketers discover distinct groups in their


customer bases, and then use this knowledge to develop
targeted marketing programs
 Land use: Identification of areas of similar land use in an
earth observation database
 Insurance: Identifying groups of motor insurance policy
holders with a high average claim cost
 Urban planning: Identifying groups of houses according to
their house type, value, and geographical location
 Seismology: Observed earth quake epicenters should be
clustered along continent faults
Notion of a Cluster can be Ambiguous

How many clusters? Six Clusters

Two Clusters Four Clusters


Notion of a Cluster can be Ambiguous
Slide from Eamonn Keogh

 What is the natural grouping of these objects

Clustering is subjective

Simpson's Family School Employees Females Males


Types of Clusterings

 Partitional Clustering
 A division of data objects into non-overlapping subsets (clusters)
 Construct various partitions and then evaluate them by some criterion

 Hierarchical clustering
 A set of nested clusters organized as a hierarchical tree
 Create a hierarchical decomposition of the set of objects using some criterion

Hierarchical Partitional
Partitional Clustering

Original Points A Partitional Clustering


Hierarchical Clustering

p1
p3 p4
p2
p1 p2 p3 p4

Traditional Hierarchical Clustering Traditional Dendrogram

p1
p3 p4
p2
p1 p2 p3 p4

Non-traditional Hierarchical Clustering Non-traditional Dendrogram


Other Distinctions Between Sets of Clusters

 Exclusive versus non-exclusive (overlapping)


– In non-exclusive clustering, points may belong to multiple
clusters.
 Can belong to multiple classes or could be ‘border’ points
– Fuzzy clustering (one type of non-exclusive)
 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
Types of Clusters

 Well-separated clusters

 Prototype-based clusters

 Contiguity-based clusters

 Density-based clusters

 Described by an Objective Function


Types of Clusters: Well-Separated

 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
Types of Clusters: Prototype-Based

 Prototype-based (center-based)
– A cluster is a set of objects such that an object in a cluster is
closer (more similar) to the prototype or “center” of a cluster,
than to the center of any other cluster
– The center of a cluster is often a centroid (continuous
attributes), the average of all the points in the cluster, or a
medoid (cetagorical attributes), the most “representative” point
of a cluster

4 center-based clusters
Types of Clusters: Contiguity-Based

 Contiguous Cluster (Nearest neighbor or


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

8 contiguous clusters
Types of Clusters: Density-Based

 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 or intertwined, and when
noise and outliers are present.

6 density-based clusters
Types of Clusters: Objective Function

 Clusters Defined by an Objective Function


– Finds clusters that minimize or maximize an objective function.
– Enumerate all possible ways of dividing the points into clusters and
evaluate the `goodness' of each potential set of clusters by using
the given objective function.
– Can have global or local objectives.
 Hierarchical clustering algorithms typically have local objectives
 Partitional algorithms typically have global objectives
– A variation of the global objective function approach is to fit the
data to a parameterized model.
 Parameters for the model are determined from the data.
 Mixture models assume that the data is a ‘mixture' of a number of
statistical distributions.
Characteristics of the Input Data Are Important

 Type of proximity or density measure


– Central to clustering
– Depends on data and application

 Data characteristics that affect proximity and/or density are


– Dimensionality
 Sparseness
– Attribute type
– Special relationships in the data
 For example, autocorrelation
– Distribution of the data

 Noise and Outliers


– Often interfere with the operation of the clustering algorithm

 Clusters of differing sizes, densities, and shapes


Clustering Algorithms

 K-means and its variants

 Hierarchical clustering

 Density-based clustering
K-means Clustering

 Partitional clustering approach


 Number of clusters, K, must be specified
 Each cluster is associated with a centroid (center point)
 Each point is assigned to the cluster with the closest
centroid
 The basic algorithm is very simple
Example of K-means Clustering

Iteration 1
3

2.5

1.5
y

0.5

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2


x
Example of K-means Clustering
Iteration 6
1
2
3
4
5
3

2.5

1.5
y

0.5

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2


x
Example of K-means Clustering
Iteration 1 Iteration 2 Iteration 3
3 3 3

2.5 2.5 2.5

2 2 2

1.5 1.5 1.5


y

y
1 1 1

0.5 0.5 0.5

0 0 0

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x x x

Iteration 4 Iteration 5 Iteration 6


3 3 3

2.5 2.5 2.5

2 2 2

1.5 1.5 1.5


y

y
1 1 1

0.5 0.5 0.5

0 0 0

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x x x
Example

 Run K-means clustering with 3 clusters (initial


centroids: 3, 16, 25) for at least 2 iterations
Example

 Centroids:
3 – 2 3 4 7 9 new centroid: 5

16 – 10 11 12 16 18 19 new centroid: 14.33

25 – 23 24 25 30 new centroid: 25.5


Example

 Centroids:
5 – 2 3 4 7 9 new centroid: 5

14.33 – 10 11 12 16 18 19 new centroid: 14.33

25.5 – 23 24 25 30 new centroid: 25.5


In class Practice

 Run K-means clustering with 3 clusters (initial


centroids: 3, 12, 19) for at least 2 iterations
K-Means Clustering Example
K-means Clustering – Details
 Simple iterative algorithm.
– Choose initial centroids;
– repeat {assign each point to a nearest centroid; re-compute cluster centroids}
– until centroids stop changing.

 Initial centroids are often chosen randomly.


– Clusters produced can vary from one run to another
 The centroid is (typically) the mean of the points in the cluster,
but other definitions are possible.
 K-means will converge for common proximity measures with
appropriately defined centroid Most of the convergence happens
in the first few iterations.
– Often the stopping condition is changed to ‘Until relatively few points
change clusters’
Evaluating K-means Clusters

 A common objective function (used with Euclidean


distance measure) is Sum of Squared Error (SSE)
– For each point, the error is the distance to the nearest cluster
center
– To get SSE, we square these errors and sum them.
K
SSE    dist 2 ( mi , x )
i 1 xCi

– x is a data point in cluster Ci and mi is the centroid (mean) for


cluster Ci
– SSE improves in each iteration of K-means until it reaches a
local or global minima.
Two different K-means Clusterings
3

2.5

2
Original Points
1.5

y
1

0.5

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2


x

3 3

2.5 2.5

2 2

1.5 1.5
y

y
1 1

0.5 0.5

0 0

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2


x x

Optimal Clustering Sub-optimal Clustering


Importance of Choosing Initial Centroids …
Iteration 5
1
2
3
4
3

2.5

1.5
y

0.5

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2


x
Importance of Choosing Initial Centroids …

Iteration 1 Iteration 2
3 3

2.5 2.5

2 2

1.5 1.5
y

y
1 1

0.5 0.5

0 0

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2


x x

Iteration 3 Iteration 4 Iteration 5


3 3 3

2.5 2.5 2.5

2 2 2

1.5 1.5 1.5


y

y
1 1 1

0.5 0.5 0.5

0 0 0

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x x x
Solutions to Initial Centroids Problem

 Multiple runs
– Helps, but probability is not on your side
 Use some strategy to select the k initial centroids
and then select among these initial centroids
– Select most widely separated
K-means++ is a robust way of doing this selection
– Use hierarchical clustering to determine initial
centroids
 Bisecting K-means
– Not as susceptible to initialization issues
K-means++ for initializalization

 This approach can be slower than random initialization,


but very consistently produces better results in terms of
SSE
 To select a set of initial centroids, C, perform the following
Bisecting K-means

 Bisecting K-means algorithm


– Variant of K-means that can produce a partitional or a
hierarchical clustering

CLUTO: http://glaros.dtc.umn.edu/gkhome/cluto/cluto/overview
Bisecting K-means Example
Limitations of K-means

 K-means has problems when clusters are of


differing
– Sizes
– Densities
– Non-globular shapes

 K-means has problems when the data contains


outliers.
– One possible solution is to remove outliers before
clustering
Limitations of K-means: Differing Sizes

Original Points K-means (3 Clusters)


Limitations of K-means: Differing Density

Original Points K-means (3 Clusters)


Limitations of K-means: Non-globular Shapes

Original Points K-means (2 Clusters)


Overcoming K-means Limitations

Original Points K-means Clusters

One solution is to find a large number of clusters such that each of them represents a part of a
natural cluster. But these small clusters need to be put together in a post-processing step.
Overcoming K-means Limitations

Original Points K-means Clusters

One solution is to find a large number of clusters such that each of them represents a part of a
natural cluster. But these small clusters need to be put together in a post-processing step.
Overcoming K-means Limitations

Original Points K-means Clusters

One solution is to find a large number of clusters such that each of them represents a part of
a natural cluster. But these small clusters need to be put together in a post-processing step.
Hierarchical Clustering

 Produces a set of nested clusters organized as a


hierarchical tree
 Can be visualized as a dendrogram
– A tree like diagram that records the sequences of
merges or splits

6 5
0.2
4
3 4
0.15 2
5
2
0.1

1
0.05
3 1

0
1 3 2 5 4 6
Strengths of Hierarchical Clustering

 Do not have to assume any particular number of


clusters
– Any desired number of clusters can be obtained by
‘cutting’ the dendrogram at the proper level

 They may correspond to meaningful taxonomies


– Example in biological sciences (e.g., animal kingdom,
phylogeny reconstruction, …)
Hierarchical Clustering

 Two main types of hierarchical clustering


– Agglomerative:
 Start with the points as individual clusters
 At each step, merge the closest pair of clusters until only one cluster
(or k clusters) left

– Divisive:
 Start with one, all-inclusive cluster
 At each step, split a cluster until each cluster contains an individual
point (or there are k clusters)

 Traditional hierarchical algorithms use a similarity or


distance matrix
– Merge or split one cluster at a time
55

An example

Let us consider a gene measured in a set of 5


experiments: A,B,C,D and E. The values measured in the
5 experiments are:
A=100 B=200 C=500 D=900 E=1100

We will construct the hierarchical clustering of these


values using Euclidean distance, centroid linkage and an
agglomerative approach.
56

An example

SOLUTION:
 The closest two values are 100 and 200
=>the centroid of these two values is 150.
 Now we are clustering the values: 150, 500, 900, 1100
 The closest two values are 900 and 1100
=>the centroid of these two values is 1000.
 The remaining values to be joined are: 150, 500, 1000.
 The closest two values are 150 and 500
=>the centroid of these two values is 325.
 Finally, the two resulting subtrees are joined in the root of
the tree.
57
An example:
Two hierarchical clusters of the expression values of a single
gene measured in 5 experiments.

1100 500 1100 900


500 900 C E D
C D E
100 200 200 100
A B B A

The dendograms are identical: both diagrams show that:


•A is most similar to B
•C is most similar to the group (A,B)
•D is most similar to E
In the left dendogram A and E are plotted far from each other
In the right dendogram A and E are immediate neighbors

THE PROXIMITY IN A HIERARCHICAL CLUSTERING DOES NOT NECESSARILY


CORRESPOND TO SIMILARITY
Agglomerative Clustering Algorithm

 Key Idea: Successively merge closest clusters


 Basic algorithm
1. Compute the proximity matrix
2. Let each data point be a cluster
3. Repeat
4. Merge the two closest clusters
5. Update the proximity matrix
6. Until only a single cluster remains

 Key operation is the computation of the proximity of two clusters


– Different approaches to defining the distance between clusters
distinguish the different algorithms
Steps 1 and 2

 Start with clusters of individual points and a


proximity matrix p1 p2 p3 p4 p5 ...
p1

p2
p3

p4
p5
.
.
. Proximity Matrix

...
p1 p2 p3 p4 p9 p10 p11 p12
Intermediate Situation

 After some merging steps, we have some clusters


C1 C2 C3 C4 C5
C1

C2
C3
C3
C4
C4
C5

Proximity Matrix
C1

C2 C5

...
p1 p2 p3 p4 p9 p10 p11 p12
Step 4

 We want to merge the two closest clusters (C2 and C5) and
update the proximity matrix. C1 C2 C3 C4 C5
C1

C2
C3
C3
C4
C4
C5

Proximity Matrix
C1

C2 C5

...
p1 p2 p3 p4 p9 p10 p11 p12
Step 5

 The question is “How do we update the proximity matrix?”


C2
U
C1 C5 C3 C4

C1 ?

C2 U C5 ? ? ? ?
C3
C3 ?
C4
C4 ?

Proximity Matrix
C1

C2 U C5

...
p1 p2 p3 p4 p9 p10 p11 p12
How to Define Inter-Cluster Distance

p1 p2 p3 p4 p5 ...
p1
Similarity?
p2

p3

p4

p5
 MIN
.
 MAX
.
 Group Average .
Proximity Matrix
 Distance Between Centroids
 Other methods driven by an objective
function
– Ward’s Method uses squared error
How to Define Inter-Cluster Similarity

p1 p2 p3 p4 p5 ...
p1

p2

p3

p4

p5
 MIN
.
 MAX
.
 Group Average .
Proximity Matrix
 Distance Between Centroids
 Other methods driven by an objective
function
– Ward’s Method uses squared error
How to Define Inter-Cluster Similarity

p1 p2 p3 p4 p5 ...
p1

p2

p3

p4

p5
 MIN
.
 MAX
.
 Group Average .
Proximity Matrix
 Distance Between Centroids
 Other methods driven by an objective
function
– Ward’s Method uses squared error
How to Define Inter-Cluster Similarity

p1 p2 p3 p4 p5 ...
p1

p2

p3

p4

p5
 MIN
.
 MAX
.
 Group Average .
Proximity Matrix
 Distance Between Centroids
 Other methods driven by an objective
function
– Ward’s Method uses squared error
How to Define Inter-Cluster Similarity

p1 p2 p3 p4 p5 ...
p1

  p2

p3

p4

p5
 MIN
.
 MAX
.
 Group Average .
Proximity Matrix
 Distance Between Centroids
 Other methods driven by an objective
function
– Ward’s Method uses squared error
MIN or Single Link

 Proximity of two clusters is based on the two


closest points in the different clusters
– Determined by one pair of points, i.e., by one link in the
proximity graph
 Example:

Distance Matrix:
Hierarchical Clustering: MIN

0.2
5
1 0.15
3
0.1
5
2 1 0.05

2 3 6 0
3 6 2 5 4 1

Dendrogram
4
4

Nested Clusters
Strength of MIN

Original Points Six Clusters

• Can handle non-elliptical shapes


Limitations of MIN

Two Clusters

Original Points

• Sensitive to noise
Three Clusters
MAX or Complete Linkage

 Proximity of two clusters is based on the two


most distant points in the different clusters
– Determined by all pairs of points in the two clusters

Distance Matrix:
Hierarchical Clustering: MAX
0.4

0.35

4 1
0.3

0.25

2 5 0.2

0.15
5
2 0.1

0.05

3 6 0
3 6 4 1 2 5
3 Dendrogram
1
4

Nested Clusters
Strength of MAX

Original Points Two Clusters

• Less susceptible to noise


Limitations of MAX

Original Points Two Clusters

• Tends to break large clusters


• Biased towards globular clusters
Group Average

 Proximity of two clusters is the average of pairwise proximity


between points in the two clusters.
 proximity(p , p )
piClusteri
i j

p jClusterj
proximity(Clusteri , Clusterj ) 
|Clusteri ||Clusterj |

Distance Matrix:
Hierarchical Clustering: Group Average

0.25

0.2
5 4 1 0.15

2 0.1
5
2 0.05

3 6
0
3 6 4 1 2 5

1 Dendrogram
4
3

Nested Clusters
Hierarchical Clustering: Group Average

 Compromise between Single and Complete


Link

 Strengths
– Less susceptible to noise

 Limitations
– Biased towards globular clusters
Hierarchical Clustering: Comparison

5
1 4 1
3
2 5
5 5
2 1 2
MIN MAX
2 3 6 3 6
3
1
4 4
4

5
1
2
5
2
3 6 Group Average
3
4 1
4
Hierarchical Clustering: Problems and Limitations

 Once a decision is made to combine two clusters,


it cannot be undone

 No global objective function is directly minimized

 Different schemes have problems with one or


more of the following:
– Sensitivity to noise
– Difficulty handling clusters of different sizes and non-
globular shapes
– Breaking large clusters

You might also like