Module 5 Notes 1
Module 5 Notes 1
No Classification Clustering
1 Supervised data Unsupervised data
2 Does highly value training sets Does not highly value training sets
3 Involves both unlabeled and labeled data Works solely with unlabeled data
Aims to identify similarities among
4 Aims to verify where a datum belongs to
data
5 Does not specify required improvement Specifies required change
6 Has two phases Has a single phase
Identifying the boundary conditions is Determining boundary conditions is
7
essential in executing the phases not paramount
8 Deals with prediction Doesn’t generally deal with prediction
Mainly employs two types of
9 Has a number of probable algorithms to use
algorithms
10 Process is more complex Process is less complex
II-Types of Clustering
The fundamental distinction between clustering types lies in whether the clusters
are nested (hierarchical) or non-nested (partitional).
Partitional Clustering
Divides data into non-overlapping subsets.
Un-nested clustering
Each data object belongs to exactly one cluster.
Partitional Provides a single flat partition of the data.
1 versus Examples: k-means, k-medoids, etc.
Hierarchical In Figure 1 (b–d), each illustration shows a valid partitional clustering with
2, 4, and 6 clusters respectively.
In Figure 1 (a–d):
Exclusive Clustering:
In exclusive clustering, each object is assigned to exactly one cluster. This
is the most straightforward form of clustering where clusters do not overlap,
and each data point has a unique assignment.
Example: The clusters in Figure 1 are all exclusive since each data object is
placed into a single cluster, with no overlap.
Fuzzy Clustering:
Fuzzy clustering is a method where every object has a degree of belonging
to every cluster, represented by a membership weight that ranges from 0 (not
belonging at all) to 1 (completely belonging).
Mathematically, fuzzy clustering treats clusters as fuzzy sets, where each
object has a membership weight associated with each cluster. The sum of the
membership weights for an object typically equals 1.
Complete Clustering:
This is useful in scenarios where the goal is to organize all available data into
distinct categories, such as organizing documents for browsing. The requirement
here is that every document or data point must be accessible within the clusters,
Complete making it essential that the clustering method covers the entire dataset.
3 versus Partial
Partial Clustering:
Unlike complete clustering, partial clustering allows for the exclusion of certain
objects from any cluster.
This is motivated by the recognition that not all objects may fit neatly into a
cluster, often due to noise, outliers, or less relevant background data. For
example, when analyzing newspaper articles to find significant topics like global
warming, partial clustering can help focus on tightly related groups of articles,
while disregarding those that are more generic or irrelevant to the primary
themes of interest.
i) Well-Separated Clusters
Clusters where each data point is closer to its own cluster than to any other cluster.
Points within a well-separated cluster are much more similar to each other than to points in other
clusters.
The distance between any two points in different groups is larger than the distance between any two
points within a group.
These groups are well-separated clusters. Figure 2(a) shows an example of well separated clusters.
Figure 2(a) Well-separated cluster. Each point is closer to all the points in its cluster than to any point in
another cluster
[
Figure 2b: Center-based clusters. Each point is closer to the center of its cluster than to the center of any other
cluster.
Continuous attributes are numeric values that can take Categorical attributes are variables that represent
an infinite number of values within a given range. distinct categories or groups.
These attributes have a finite number of distinct values
Examples: or categories, and these categories are often not
Height: A person’s height can be 170.5 cm, 172.3 cm, numerical (though they can be coded as numbers).
etc. Examples:
Weight: A person’s weight might be 65.2 kg, 67.8 kg, etc. Color: Categories like red, blue, green.
Type of Animal: Categories like dog, cat, bird.
iii) Graph-Based
• If the data is represented as a graph in which group of objects are connected to one another, but that
have no connection to objects outside the group.
• An important example of graph-based clusters are Contiguity-based clusters, where two objects
are connected only if they are within a specified distance of each other. This implies that each
object in a contiguity-based cluster is closer to some other object in the cluster than to any point in a
different cluster.
Figure 2(c): contiguity based clusters [4] each point is closer to at least one point in its cluster than to any
point in another cluster.
• This definition of a cluster is useful when clusters are irregular or intertwined. However, this approach
can have trouble when noise is present since, as illustrated by the two spherical clusters of Figure -
2(c), a small bridge of points can merge two distinct clusters.
iv) Density-Based
• Density based clusters are the regions of high density separated by a region of low density.
• A density based definition of a cluster is often employed when the clusters are irregular or intertwined,
and when noise and outliers are present.
• By contrast, a contiguity based definition of a cluster would not work well for the data since the noise
would tend to form bridges between clusters.
• Figure-2(d) shows few density-based clusters created by adding noise to the data of Figure-2(c).
Figure (2d) Density-Based clusters: Clusters are regions of high density separated by regions of low density.
Note: The two circular clusters are not merged, as in Figure 2(c), because the bridge between them fades into the noise.
Likewise, the curve that is present in Figure-2(c) also fades into the noise and does not form a cluster in Figure-2(d).
Figure-2(e) Conceptual clusters. Points in a cluster share some general property that derives from the entire
set of points. (Points in the intersection of the circles belong to both.)
IV- K - Means
K-means defines a prototype in terms of a centroid, which is usually the mean of a group of points, and is
typically applied to objects in a continuous n-dimensional space.
• K-medoid defines a prototype in terms of a medoid, which is the most representative point for a group
of points, and can be applied to a wide range of data since it requires only a proximity measure for a pair
of objects.
The Basic K-means Algorithm
The k-means algorithm for partitioning, where each cluster’s center is represented by the mean value of the
objects in the cluster.
Input K: the number of clusters,
D: a data set containing n objects
Output A set of k clusters
Algorithm
Explanation:
First choose K initial centroids, where K is a user specified parameter, namely, the
number of clusters desired.
Each point is then assigned to the closest centroid, and each collection of points
assigned to a centroid is a cluster.
The centroid of each cluster is then updated based on the points assigned to the
cluster.
Repeat the assignment and update steps until no point changes clusters, or
equivalently, until the centroids remain the same.
Bisecting K-means
– The bisecting K-means algorithm is a straightforward extension of the basic K-means algorithm that is based
on a simple idea:
– To obtain K clusters, split the set of all points into two clusters, select one of these clusters to split, and so
on, until K clusters have been produced.
Bisecting K-
means
Algorithm.
Explanation
Figure-4: Two pairs of clusters with a pair of initial centroids within each pair of clusters.
V-Hierarchical Clustering
Hierarchical clustering techniques are a second important category of clustering methods. As with K-means,
these approaches are relatively old compared to many clustering algorithms, but they still enjoy widespread
use. There are two basic approaches for generating a hierarchical clustering
1. Agglomerative: Start with the points as individual clusters and, at each step, merge the closest pair of
clusters. This requires defining a notion of cluster proximity.
2. Divisive : Start with one, all-inclusive cluster and, at each step, split a cluster until only singleton clusters
of individual points remain. In this case, we need to decide which cluster to split at each step and how to
do the splitting.
Agglomerative Hierarchical Clustering: Use distance matrix as clustering criteria. This method does not
require the number of clusters k as an input, but needs a termination condition
VI-Graph-based Clustering
Cluster Proximity Definitions - Graph-based
MAX takes the proximity between the farthest two points in different clusters to be the cluster
proximity, or using graph terms, the longest edge between two nodes in different subsets of
nodes.
If our proximities are distances, then the names, MIN and MAX, are short and suggestive.
3) Group Average:
Group average defines cluster proximity to be the average pairwise proximities (average length
of edges) of all pairs of points from different clusters
dist({3, 6}, {4}) = max(dist(3, 4), dist(6, 4)) = max(0.15, 0.22) = 0.22.
dist({3, 6}, {2, 5}) = max(dist(3, 2), dist(6, 2), dist(3, 5), dist(6, 5)) = max(0.15, 0.25, 0.28, 0.39) = 0.39.
dist({3, 6}, {1}) = max(dist(3, 1), dist(6, 1)) = max(0.22, 0.23) = 0.23.
3) Group Average:
Classification of Points According to Center-Based Density: The center-based approach to density allows
us to classify a point as being
(1) in the interior of a dense region (a core point),
(2) on the edge of a dense region (a border point), or
(3) In a sparsely occupied region (a noise or background point).
Figure-7 graphically illustrates the concepts of core, border, and noise points using a collection of two-
dimensional points.
Two parameters are required to define the core, border and noise points
i) Eps: Maximum radius of the neighborhood.
NEps(p): {q belongs to D | dist(p,q) ≤ Eps}
Core points
• These points are in the interior of a density-based cluster.
• A point is a core point if the number of points within a given neighborhood around the point as
determined by the distance function
– User specified distance parameter, Eps, exceeds a certain threshold, MinPts, which is also a user-
specified parameter.
• A point is a core point if there are at least MinPts within a distance of Eps, where MinPts and Eps are
user-specified parameters. In Figure 7, point A is a core point for the radius (Eps) if MinPts ≥ 7.
Border points
– A border point is not a core point, but falls within the neighborhood of a core point.
– A border point can fall within the neighborhoods of several core points.
– In Figure 7, point B is a border point. A border point can fall within the neighborhoods of several
core points.
Noise points
A noise point, is any point that is neither a core point nor a border point.
In Figure 7, point C is a noise point.
Two Definitions
i) Density-reachable:
A point p is density-reachable from a point q w.r.t. Eps, MinPts if there is a chain of points p1, …, pn,
p1 = q, pn = p such that pi+1 is directly density-reachable from pi i.e. if
– p belongs to NEps(q)
– core point condition: |NEps (q)| ≥ MinPts
Density-connected:
A point p is density-connected to a point q w.r.t. Eps, MinPts if there is a point o such that both, p and q are
density-reachable from o w.r.t. Eps and MinPts
DBSCAN Algorithm
PROBLEM: Apply the DBSCAN algorithm to the given data points and create the clusters
with min_samples = 4 and epsilon (ϵ) = 1.9 p1 (3,7) p2(4,6) p3(5,5) p4(6,4) p5(7,3)
p6(6,2) p7(7, 2) p8(8,4) p9(3,3) p10(2,6) p11(3,5) p12(2,4)
Solution: Calculate the distance between each points using Euclidian distance
• Single link: smallest distance between an element in one cluster and an element in the
other, i.e., dis(Ki, Kj) = min(tip, tjq)
• Complete link: largest distance between an element in one cluster and an element in the
other, i.e., dis(Ki, Kj) = max(tip, tjq)
• Average: avg distance between an element in one cluster and an element in the other,
i.e., dis(Ki, Kj) = avg(tip, tjq)
• Centroid: distance between the centroids of two clusters, i.e., dis(Ki, Kj) = dis(Ci, Cj)
• Medoid: distance between the medoids of two clusters, i.e., dis(Ki, Kj) = dis(Mi, Mj)
– Medoid: one chosen, centrally located object in the cluster
In supervised classification, the evaluation of the classification model is an integral part of the
process of developing a classification model, and there are well-accepted evaluation measures
and procedures, e.g., accuracy and cross-validation, respectively.
Many times, cluster analysis is conducted as a part of an exploratory data analysis. Hence,
evaluation seems to be an unnecessarily complicated addition to what is supposed to be an
informal process.
Furthermore, because there are a number of different types of clusters—in some sense, each
clustering algorithm defines its own type of cluster—it can seem that each situation might
require a different evaluation measure. For instance, K-means clusters might be evaluated in
terms of the SSE, but for density-based clusters, which need not be globular, SSE would not
work well at all.
Nonetheless, cluster evaluation should be a part of any cluster analysis. A key motivation is
that almost every clustering algorithm will find clusters in a data set, even if that data set has
no natural cluster structure.
For instance, consider Figure 8, which shows the result of clustering 100 points that are
randomly (uniformly) distributed on the unit square.
The original points are shown in Figure 8(a), while the clusters found by DBSCAN, K-means,
and complete link are shown in Figures 8(b), 8(c), and 8(d), respectively.
Since DBSCAN found three clusters (after we set Eps by looking at the distances of the fourth
nearest neighbors), we set K-means and complete link to find three clusters as well. (In Figure
8(b) the noise is shown by the small markers.) However, the clusters do not look compelling
for any of the three methods. In higher dimensions, such problems cannot be so easily detected.
Being able to distinguish whether there is non-random structure in the data is just one
important aspect of cluster validation.
Notice that items 1, 2, and 3 do not make use of any external information— they are
unsupervised techniques, while item 4 requires external information.
A further distinction can be made with respect to items 3, 4, and 5: Do we want to evaluate the
entire clustering or just individual clusters?
The evaluation measures, or indices, that are applied to judge various aspects of cluster
validity are traditionally classified into the following three types.
1. Unsupervised.
Measures the goodness of a clustering structure without respect to external information. An
example of this is the SSE. Unsupervised measures of cluster validity are often further
divided into two classes: measures of cluster cohesion (compactness, tightness), which
determine how closely related the objects in a cluster are, and measures of cluster separation
(isolation), which determine how distinct or well separated a cluster is from other clusters.
Unsupervised measures are often called internal indices because they use only information
present in the data set.
2. Supervised.
Measures the extent to which the clustering structure discovered by a clustering algorithm
matches some external structure. An example of a supervised index is entropy, which
measures how well cluster labels match externally supplied class labels. Supervised
measures are often called external indices because they use information not present in the
data set.
3. Relative.
Compares different clustering’s or clusters. A relative cluster evaluation measure is a
supervised or unsupervised evaluation measure that is used for the purpose of comparison.
Thus, relative measures are not actually a separate type of cluster evaluation measure, but
are instead a specific use of such measures. As an example, two K-means clustering’s can
be compared using either the SSE or entropy.
Unsupervised cluster evaluation, beginning with
(1) measures based on cohesion and separation, and
(2) two techniques based on the proximity matrix
The validity function can be cohesion, separation, or some combination of these quantities. The
weights will vary depending on the cluster validity measure. In some cases, the weights are
simply 1 or the size of the cluster, while in other cases to be discussed a bit later, they reflect a
more complicated property of the cluster.
From a graph-based view, the cohesion of a cluster can be defined as the sum of the weights of
the links in the proximity graph that connect points within the cluster. See Figure 9(a). (Recall
that the proximity graph has data objects as nodes, a link between each pair of data objects, and
a weight assigned to each link that is the proximity between the two data objects connected by
the link.) Likewise, the separation between two clusters can be measured by the sum of the
weights of the links from points in one cluster to points in the other cluster. This is illustrated
in Figure 9(b).
For prototype-based clusters, the cohesion of a cluster can be defined as the sum of the
proximities with respect to the prototype (centroid or medoid) of the cluster. Similarly, the
separation between two clusters can be measured by the proximity of the two cluster
prototypes. This is illustrated in Figure-10, where the centroid of a cluster is indicated by a “+”.
where ci is the prototype (centroid) of cluster Ci and c is the overall prototype (centroid). There
are two measures for separation because, the separation of cluster prototypes from an overall
prototype is sometimes directly related to the separation of cluster prototypes from one another.
(This is true, for example, for Euclidean distance.) Note that Cohesion Equation, is the cluster
SSE if we let proximity be the squared Euclidean distance.
While the graph-based and prototype-based approaches to measuring the cohesion and
separation of a cluster seem distinct, for some proximity measures they are equivalent. For
instance, for the SSE and points in Euclidean space, it can be shown (from the following
equation ) that the average pairwise distance between the points in a cluster is equivalent to the
SSE of the cluster.
It is straightforward to show that the total SSB is directly related to the pairwise distances
between the centroids. In particular, if the cluster sizes are equal, i.e., mi = m/K, then this
relationship takes the simple form given by
For some validity measures, there is also a strong relationship between cohesion and separation.
Specifically, it is possible to show that the sum of the total SSE and the total SSB is a constant;
i.e., that it is equal to the total sum of squares (TSS), which is the sum of squares of the distance
of each point to the overall mean of the data. The importance of this result is that minimizing
SSE (cohesion) is equivalent to maximizing SSB (separation).
It can also be shown that there is a relationship between graph- and centroidbased
cohesion measures for Euclidean distance. For simplicity, we once again
assume one-dimensional data.
Sum of the squared error (SSE): We calculate the error of each data point, i.e., its
Euclidean distance to the closest centroid, and then compute the total sum of the squared
errors.
• Given two different sets of clusters that are produced by two different runs of K-
means, we prefer the one with the smallest squared error since this means that the
prototypes (centroids) of this clustering are a better representation of the points in
their cluster.
Two strategies that decrease the total SSE by increasing the number of clusters are the
following:
• Split a cluster
– The cluster with the largest SSE is usually chosen, but we could also split the
cluster with the largest standard deviation for one particular attribute.
Two strategies that decrease the number of clusters, while trying to minimize the increase in
total SSE, are the following:
• Disperse a cluster
– This is accomplished by removing the centroid that corresponds to the cluster and
re-assigning the points to other clusters.
– Ideally, the cluster that is dispersed should be the one that increases the total SSE
the least.
– The clusters with the closest centroids are typically chosen, although another,
perhaps better, approach is to merge the two clusters that result in the smallest
increase in total SSE.
– These two merging strategies are the same ones that are used in the hierarchical
clustering techniques known as the centroid method