7 Cluster Analysis

Data Warehousing and Data Mining · Unit 7 · 8 hrs

Cluster Analysis

Exam-focused notes for Cluster Analysis (Data Warehousing and Data Mining, CSC420): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.

Cluster Analysis in short

Clustering groups a set of objects into classes of similar objects without being told the classes in advance, which is what makes it an unsupervised technique. This unit works through the distance measures clustering relies on, then traces k-means, k-means++, k-medoids, single-linkage hierarchical clustering and DBSCAN iteration by iteration on small concrete point sets, checking every distance and every centroid update along the way.

Cluster Analysis: notes

Types of data in cluster analysis

The data fed into cluster analysis can be interval-scaled, ordinal or categorical, and a mixture of these types in one data set makes the analysis considerably harder, because clustering fundamentally needs a way of measuring the distance, or dissimilarity, between two observations, and the right distance measure depends on which of these types is being compared. A number of distance measures exist specifically to handle binary and categorical attributes, since the ordinary geometric distances below only make direct sense for numeric, interval-scaled data.

Similarity and dissimilarity between objects

Distance measures quantify how similar or dissimilar two data objects are, and clustering algorithms are built entirely on top of whichever distance measure is chosen. The most widely used is Euclidean distance,

$$ d(x,y) = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}, \qquad x=(x_1,y_1),\ y=(x_2,y_2) $$

which generalizes to any number of dimensions by summing squared differences across all of them. Another common choice is Manhattan (city block) distance,

$$ d(x,y) = |x_2-x_1| + |y_2-y_1| $$

which sums absolute differences along each axis rather than taking their straight-line combination, and is often preferred when movement is naturally constrained to axis-aligned steps (as in a city grid) or when it should be less sensitive to a single large difference in one dimension.

What this unit covers

  • Types of data in cluster analysis
  • Similarity and dissimilarity between objects
  • Clustering techniques: Partitioning (k-means, k-means++, Mini-Batch k-means, k-medoids)
  • Hierarchical (Agglomerative and Divisive)
  • Density based (DBSCAN)
  • Outlier analysis

Clustering techniques

2081 · 5 marks

Using k-means++ algorithm and Euclidean distance, find the initial 3 cluster centroids from A1 = (3, 11), A2 = (3, 6), A3 = (9, 5), A4 = (6, 9), A6 = (7, 5), A7 = (2, 3), A8 = (5, 10). Choose (3, 11) as one of the initial centroids. [5]

Show solved answer

K-Means++ Initial Centroid Selection

Given

Data points:

PointCoordinates
A1(3, 11)
A2(3, 6)
A3(9, 5)
A4(6, 9)
A6(7, 5)
A7(2, 3)
A8(5, 10)

Number of clusters: $k = 3$ First centroid (given): $C_1 = (3, 11)$

Solution

K-Means++ Rule

  1. First centroid is fixed as $C_1 = (3,11)$.
  2. For each point compute $D^2$ = squared Euclidean distance to the nearest chosen centroid.
  3. Choose the point with the largest $D^2$ (highest selection probability) as the next centroid.

Selecting $C_2$: distances to $C_1 = (3,11)$

$$D^2 = (x-3)^2 + (y-11)^2$$

PointCalculation$D^2$
A2 (3,6)$0 + 25$25
A3 (9,5)$36 + 36$72
A4 (6,9)$9 + 4$13
A6 (7,5)$16 + 36$52
A7 (2,3)$1 + 64$65
A8 (5,10)$4 + 1$5

Total $= 25+72+13+52+65+5 = 232$

Probability $= D^2 / 232$:

PointP
A20.108
A30.310
A60.224
A70.280
A40.056
A80.022

Largest $D^2$ is A3 (72).

$$\boxed{C_2 = (9, 5)}$$

Selecting $C_3$: nearest distance to ${C_1, C_2}$

$D^2(C_2)$ with $C_2 = (9,5)$:

Point$D^2(C_1)$$D^2(C_2)$$\min$
A2 (3,6)25$36+1=37$25
A4 (6,9)13$9+16=25$13
A6 (7,5)52$4+0=4$4
A7 (2,3)65$49+4=53$53
A8 (5,10)5$16+25=41$5

Total $= 25+13+4+53+5 = 100$

Probability $= \min D^2 / 100$:

PointP
A20.25
A40.13
A60.04
A70.53
A80.05

Largest $\min D^2$ is A7 (53).

$$\boxed{C_3 = (2, 3)}$$

Final Result

The 3 initial centroids chosen by K-Means++ are:

CentroidCoordinates
$C_1$(3, 11)
$C_2$(9, 5)
$C_3$(2, 3)
Open this answer on its own page →

2081 · 5 marks

Differentiate between k-means and k-medoids clustering algorithm. [5]

Both K-Means and K-Medoids are partitioning-based clustering algorithms that divide a dataset of n objects into k clusters. However, they differ significantly in how they represent cluster centers and handle data. --- Feature K-Means K-Medoids --------- Center Representation Uses the mean (averag...

Open this answer on its own page →

2080 · 5 marks

How K-medoids clustering differs from K-means clustering? Divide the following data points into two clusters using kmedoids algorithm. Show computation up to 3 iterations. {(70,85), (65,80), (72,88), (75,90), (60,50), (64,55), (62,52), (63,58)}. [5]

Data points (8 points), to be split into $k = 2$ clusters: Label Point ------ P1 (70, 85) P2 (65, 80) P3 (72, 88) P4 (75, 90) P5 (60, 50) P6 (64, 55) P7 (62, 52) P8 (63, 58) Requirements: show computation up to 3 iterations. Distance metric not specified, so I use Manhattan distance

Open this answer on its own page →

2079 · 5 marks

Discuss the concept of K-means++ and Mini-batch K-means algorithm. [5]

--- In the standard K-means algorithm, the initial cluster centers (centroids) are chosen randomly. This random initialization leads to a problem called initialization sensitivity, where the final clusters formed depend heavily on which points were chosen initially. Poor initialization can result...

Open this answer on its own page →

2078 · 5 marks

Apply K(=2)-Means algorithm over the data (185, 72), (170, 56), (168, 60), (179, 68), (182, 72), (188, 77) up to two iterations and show the clusters. Initially choose first two objects as initial centroids. [5]

Point Data ------------- P1 (185, 72) P2 (170, 56) P3 (168, 60) P4 (179, 68) P5 (182, 72) P6 (188, 77) Initial Centroids: $C1 = (185, 72)$, $C2 = (170, 56)$ Distance metric: Euclidean, $d = \sqrt{(x2-x1)^2 + (y2-y1)^2}$ --- Distances to $C1=(185,72)$: - P1: $\sqrt{0+0}=0$ - P2:

Open this answer on its own page →

Density based

2080 · 5 marks

Discuss working of DBSCAN algorithm. [5]

DBSCAN stands for Density-Based Spatial Clustering of Applications with Noise. It is a density-based clustering method where clusters are defined as dense regions in the data space, separated by regions of lower density points. The key idea is: for each point of a cluster, the neighborhood of a g...

Open this answer on its own page →

2078 · 10 marks

How do you compare two classifiers? Given the points A(3,7), B(4,6), C(5,5), D(6,4), E(7,3), F(6,2), G(7,2) and H(8,4), find the core points, border points and outliers using DBSCAN. Take Eps 2.5 and MinPts = 3.[10]

Two classifiers can be compared using the following techniques: 1. Confusion Matrix based metrics Build a confusion matrix (TP, TN, FP, FN) for each classifier and compute: - Accuracy $= \dfrac{TP+TN}{TP+TN+FP+FN}$ - Precision $= \dfrac{TP}{TP+FP}$ - Recall $= \dfrac{TP}{TP+FN}$ - F1-score

Open this answer on its own page →

Hierarchical

2079 · 5 marks

What are two categories of hierarchical clustering? Divide the following data points into two clusters using agglomerative clustering. { (2,10), (2,5), (8,4), (5,8), (7,5), (6,4) } [5]

Show solved answer

Hierarchical Clustering: Two Categories and Agglomerative Example

Given

Data points to cluster:

  • P1 = (2, 10)
  • P2 = (2, 5)
  • P3 = (8, 4)
  • P4 = (5, 8)
  • P5 = (7, 5)
  • P6 = (6, 4)

Target: 2 clusters. Linkage method not specified; I will use single linkage (minimum distance) as is standard for this textbook problem.


Solution

Two Categories of Hierarchical Clustering

  1. Agglomerative (Bottom-Up): Each object starts as its own cluster. At each step the two closest clusters are merged, continuing until all objects form one cluster (or the desired number is reached).

  2. Divisive (Top-Down): All objects start in a single cluster, which is repeatedly split into smaller clusters until each object is alone (or the desired number is reached).


Distance Formula (Euclidean)

$$d(P_i, P_j) = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$$

Initial Distance Matrix

P1P2P3P4P5P6
P105.009.225.399.069.22
P25.0006.084.245.004.12
P39.226.0805.832.242.00
P45.394.245.8303.615.00
P59.065.002.243.6101.41
P69.224.122.005.001.410

Sample checks:

  • $d(P5,P6)=\sqrt{1^2+1^2}=1.41$ (minimum)
  • $d(P3,P6)=\sqrt{2^2+0^2}=2.00$
  • $d(P3,P5)=\sqrt{1^2+1^2}=2.24$

Step A: Merge closest pair

Minimum = 1.41 (P5, P6). Merge → C1 = {P5, P6}

Clusters: {P1}, {P2}, {P3}, {P4}, {P5,P6}

Step B: Recompute (single linkage)

  • $d({P5,P6},P1)=\min(9.06,9.22)=9.06$
  • $d({P5,P6},P2)=\min(5.00,4.12)=4.12$
  • $d({P5,P6},P3)=\min(2.24,2.00)=2.00$ ← minimum overall
  • $d({P5,P6},P4)=\min(3.61,5.00)=3.61$

Merge P3 → C1 = {P3, P5, P6}

Clusters: {P1}, {P2}, {P4}, {P3,P5,P6}

Step C: Recompute

  • $d({P3,P5,P6},P1)=\min(9.22,9.06,9.22)=9.06$
  • $d({P3,P5,P6},P2)=\min(6.08,5.00,4.12)=4.12$
  • $d({P3,P5,P6},P4)=\min(5.83,3.61,5.00)=3.61$ ← minimum overall

(Others: $d(P1,P2)=5.00,\ d(P1,P4)=5.39,\ d(P2,P4)=4.24$)

Merge P4 → C1 = {P3, P4, P5, P6}

Clusters: {P1}, {P2}, {P3,P4,P5,P6}

Step D: Recompute

  • $d({P3,P4,P5,P6},P1)=\min(9.22,5.39,9.06,9.22)=5.39$
  • $d({P3,P4,P5,P6},P2)=\min(6.08,4.24,5.00,4.12)=4.12$
  • $d(P1,P2)=5.00$

Minimum = 4.12 (between big cluster and P2). Merge P2 → C1 = {P2, P3, P4, P5, P6}

Clusters: {P1}, {P2,P3,P4,P5,P6}


Final Result (2 clusters)

We stop when exactly two clusters remain:

$$\boxed{\text{Cluster 1} = {P1} = {(2,10)}}$$ $$\boxed{\text{Cluster 2} = {P2,P3,P4,P5,P6} = {(2,5),(8,4),(5,8),(7,5),(6,4)}}$$

Point P1 = (2,10) is the outlier that separates last, forming its own cluster; all other points group together.

Open this answer on its own page →

Types of data in cluster analysis

2075 · 5 marks

What is the purpose of cluster analysis in data mining? Explain. [5]

Cluster analysis is a data mining technique in which data objects are grouped into clusters based on their similarity. Objects within the same cluster have high similarity to one another, while objects belonging to different clusters are dissimilar to each other. Importantly, in cluster analysis ...

Open this answer on its own page →