Data Mining Techniques: Worked Examples of Classification, Clustering and Association Rules

Learn how to identify a data-mining task by its output, then check the calculation with small examples for k-NN, linear regression, k-means, association rules and evaluation metrics.

KnowledgeGate Team

Exam prep & CS education

Updated 25 Nov 20265 min read
Data Mining Techniques: Worked Examples of Classification, Clustering and Association Rules

Classification, clustering and association rules are easy to memorise as names. The difficulty starts when an objective question changes the required output or one denominator. Classification, regression, k-means clustering and association rules answer different questions, and their outputs can be computed from fixed values. Small values make the calculations easy to check by hand, while the same logic applies to larger stored datasets.

Data mining techniques: choose the output before the algorithm

Data mining discovers useful patterns or predictive relationships in prepared data. In the broader knowledge-discovery flow, we select data, clean it, transform it, mine patterns, evaluate them and present the useful result.

A data warehouse has a different job: it integrates and stores historical data. OLAP lets an analyst slice, dice and aggregate that data through directed queries. Mining discovers a model or pattern instead. The DBMS topic guide places these ideas in their wider database context.

Question

Output

Technique

Labelled target needed?

Which class?

Categorical label

Classification

Yes

What numeric value?

Number

Regression

Yes

Which natural groups?

Cluster IDs

Clustering

No

Which items occur together?

Rules of the form X then Y

Association rule mining

No

Which record is unusual?

Anomaly score or flag

Anomaly detection

Sometimes

Use one test throughout: if the target column is known during training, the task is supervised. If the structure must be discovered without that target, it is unsupervised.

Classification and regression: compute two supervised predictions

For 3-nearest-neighbour classification, take labelled training records A=(2,1), Regular, B=(3,2), Regular, C=(6,5), Premium and D=(7,7), Premium. The unlabelled query is Q=(5,4).

Using Euclidean distance:

  • d(Q,A)=sqrt((5-2)^2+(4-1)^2)=sqrt(18)=4.243

  • d(Q,B)=sqrt((5-3)^2+(4-2)^2)=sqrt(8)=2.828

  • d(Q,C)=sqrt((5-6)^2+(4-5)^2)=sqrt(2)=1.414

  • d(Q,D)=sqrt((5-7)^2+(4-7)^2)=sqrt(13)=3.606

The order is C, B, D, A. With k=3, Premium gets two votes and Regular gets one, so Q is Premium. Choosing k=1 also returns Premium here, but another dataset need not agree.

Regression predicts a number. For (visits, monthly spend) pairs (1,140), (2,180), (3,220), (4,260), x_bar=2.5 and y_bar=200. The cross-product sum is 200, while the squared-x sum is 5. Therefore b1=200/5=40, b0=200-(40*2.5)=100, and the line is y=100+40x. At x=5, it predicts 300. These spend figures are invented for the example. Both tasks are supervised, but k-NN uses local votes while regression estimates a numeric relationship.

K-means clustering: follow assignments, centroids and SSE

K-means trace showing point assignments, updated centroids, unchanged clusters, and SSE 1.50.

Take unlabelled points P1=(1,1), P2=(2,1), P3=(4,3) and P4=(5,4), with k=2. Start at mu1=(1,1) and mu2=(5,4).

For P1, the distances to the two centroids are 0 and 5. For P2, they are 1 and sqrt(18)=4.243. Both join C1. For P3, the distances are sqrt(13)=3.606 and sqrt(2)=1.414; for P4, they are 5 and 0. Both join C2.

Now recompute the centroids:

  • mu1=((1+2)/2,(1+1)/2)=(1.5,1)

  • mu2=((4+5)/2,(3+4)/2)=(4.5,3.5)

Reassignment keeps the same clusters, so the algorithm stops. The final squared-error contributions are 0.25, 0.25, 0.50 and 0.50, giving SSE=1.50.

These clusters have no pre-existing Regular or Premium labels. Initial centroids and feature scale can change the result. K-means fits numeric, roughly compact groups better than arbitrary shapes.

Two-panel k-means plot: points P1 to P4 with initial centroids (1,1) and (5,4), then final centroids (1.5,1) and (4.5,3.5) with SSE 1.50.

Association-rule mining: calculate support, confidence and lift

Use six baskets: T1={Rice, Tea}, T2={Rice, Soap}, T3={Rice, Soap, Coffee}, T4={Rice, Tea, Soap}, T5={Tea, Oil} and T6={Rice, Oil}.

With minimum support 50%, Rice occurs in five baskets, Soap in three, and {Rice, Soap} in three. Their supports are therefore 5/6=83.3%, 3/6=50% and 3/6=50%. The pair is frequent.

Direction matters for confidence:

  • confidence(Rice -> Soap)=3/5=60%

  • confidence(Soap -> Rice)=3/3=100%

Lift is the same in both directions: 0.60/0.50=1.20, or equivalently 1.00/(5/6)=1.20. With a sample minimum confidence of 60%, both rules qualify.

Support measures prevalence. Confidence measures conditional reliability, so its denominator is the antecedent. Lift compares that reliability with the consequent's baseline prevalence. Itemset support is symmetric, but rule confidence is not. Here, lift=1.20 indicates positive association in this toy sample. It does not prove that one item causes the other.

Anomaly detection and summarisation: useful outputs beyond the big four

Consider transaction amounts [100, 105, 98, 102, 500]. Their median is 102. The absolute deviations are [2,3,4,0,398], whose median is MAD=3. For 500, the modified z-score is 0.6745*(500-102)/3=89.48, far above an example flag threshold of 3.5.

That threshold is an analytical choice, not a universal law. A flag calls for investigation; it does not prove fraud.

Summarisation produces a compact profile, such as five records, median 102, range 98 to 500. Sequential-pattern mining preserves order, for example view product -> add to cart -> purchase. Association baskets capture co-occurrence but do not preserve that order.

Data preparation and evaluation: stop a correct formula answering the wrong question

Useful mining starts with cleaning, a missing-value policy, duplicate handling and categorical encoding. Scale also matters. If visits range from 1 to 9, then 5 becomes (5-1)/(9-1)=0.5. If spend ranges from 100 to 900, then 500 becomes (500-100)/(900-100)=0.5. Scaling prevents a large numeric range from dominating distances in k-NN or k-means. Fit the scaler only on training data, because test-data fitting leaks information.

For a 40-case classification result with TP=12, TN=20, FP=3 and FN=5:

Metric

Calculation

Result

Accuracy

(12+20)/40

80%

Precision

12/(12+3)

80%

Recall

12/(12+5)

70.6%

F1

2*12/(2*12+3+5)=24/32

75%

Accuracy alone can conceal missed positives, which recall exposes. Classification uses a held-out confusion matrix and related metrics. Regression can use MAE or RMSE, clustering can compare cohesion and separation, and association rules use support, confidence and lift. The GATE CS exam preparation page covers the wider subject.

Data mining exam patterns: identify the task, then calculate the metric

Repeatable question forms ask you to choose a technique from its output, perform one k-means assignment or centroid update, separate class labels from cluster IDs, calculate support, confidence or lift, read a confusion matrix, or spot leakage and unsuitable feature scale.

Trap

Correction

Classification = clustering

Classification needs labelled classes

Support(A -> B) changes with direction

support(A union B) is symmetric

confidence(A -> B)=confidence(B -> A)

The denominators differ

High confidence proves causation

Association is not causation

A data warehouse performs mining

A warehouse stores integrated data; mining discovers patterns

Use the DBMS MCQs for broader topic practice, then the GATE Test Series for timed application.

Data mining techniques: the short decision rule

  • A categorical target means classification.

  • A numeric target means regression.

  • No target and natural groups means clustering.

  • Co-occurrence means association rules.

  • Unusual records mean anomaly detection.

In the worked examples, Q becomes Premium at k=3, k-means stops at (1.5,1) and (4.5,3.5) with SSE=1.50, and the Rice-Soap rule has lift=1.20. If you are building a complete subject sequence, use GATE Guidance by Sanchit Sir. If you are revising only this topic, first recompute all four examples without looking at the answers.