Blog
Data Mining Past Paper 2016 – BSCS 7th Term UOS (CS-471)
University of Sargodha Data Mining (CS-471) paper for BS Computer Science 7th term, 2016 exam (80 marks, 2:30 hours). The paper has been retyped, and solved answers are given below for all 16 short questions and all five long questions, including K-means vs K-medoids, agglomerative clustering of the given points, FP-Growth and naïve Bayes.
Solved answers
Q1 – Short answers (16 × 2)
A. Supervised learning: Learning from labelled training data where the correct output is known, to predict the output for new data, e.g. classification and regression.
B. Unsupervised learning: Learning from unlabelled data to find hidden structure, e.g. clustering and association rule mining.
C. Descriptive data mining: Mining that describes general properties of existing data, e.g. clustering, association rules and summarisation (as opposed to predictive mining).
D. “Maximal” in maximal frequent pattern mining: A frequent itemset is maximal if no proper superset of it is frequent. Mining only maximal patterns gives a small set from which all frequent itemsets can be derived (but not their exact supports).
E. A technique more efficient than Apriori: FP-Growth – it compresses the database into an FP-tree and mines frequent itemsets without generating candidates, scanning the database only twice. (Eclat is another.)
F. Nominal data: Categorical data whose values are names or labels with no order, e.g. colour {red, green, blue}, city, gender.
G. Example of ordinal data: Values with a meaningful order but unknown differences, e.g. grades A, B, C; size small < medium < large; rating poor/good/excellent.
H. Polarity (dissimilarity) for nominal data: Using simple matching: d(i, j) = (p − m)/p, where p is the number of attributes and m the number of matches. (For binary values, polarity is positive/negative – e.g. yes/no.)
I. Knowledge: Useful, understandable patterns or rules derived from data and information that support decisions, e.g. “customers who buy bread usually buy milk”.
J. Support: The fraction (or count) of transactions that contain an itemset: support(A ⇒ B) = P(A ∪ B).
K. Confidence: How often the rule is true: confidence(A ⇒ B) = support(A ∪ B) / support(A) = P(B | A).
L. Time consumed by K-means: O(n·k·t) (× d for dimensions), where n = objects, k = clusters, t = iterations – efficient for large data because k, t ≪ n.
M. A disadvantage of K-means: It is sensitive to outliers and noise (the mean is pulled by extreme values); it also needs k in advance and finds only spherical clusters.
N. Why K-medoids is better than K-means: K-medoids uses actual data objects (medoids) as cluster centres, so it is robust to outliers and noise, and works with any dissimilarity measure.
O. Posterior probability: The probability of a hypothesis after seeing the data: P(H | X) = P(X | H)·P(H) / P(X) (Bayes’ theorem), e.g. probability a customer buys given age and income.
P. Entropy: A measure of impurity or uncertainty of a set: H(S) = −Σ pᵢ log₂ pᵢ. It is 0 for a pure set and 1 for an even two-class split; used in ID3 to compute information gain.
Q2 – K-means vs K-medoids
| K-means | K-medoids (PAM) |
|---|---|
| Cluster centre = mean of points (may not be a real point) | Cluster centre = medoid, an actual data object |
| Sensitive to outliers and noise | Robust to outliers and noise |
| Minimises sum of squared Euclidean distances | Minimises sum of dissimilarities (any distance) |
| Works on numeric data only | Works on any data with a distance measure |
| Fast: O(nkt) | Slower: O(k(n−k)²) per iteration |
| Good for large datasets | Better for small/medium datasets (CLARA/CLARANS for large) |
K-means steps: choose k centroids; assign each point to the nearest centroid; recompute means; repeat until no change.
K-medoids (PAM) steps: choose k medoids; assign points to the nearest medoid; for each medoid try swapping it with a non-medoid and keep the swap if total cost decreases; repeat until no improvement.
Q3 – Agglomerative clustering
Points: A(2,4), B(5,6), C(6,5), D(5,8), E(6,6), F(7,7), G(2,8). Start with each point as a cluster, use Euclidean distance and single linkage (minimum distance between clusters) and merge the closest pair at each step.
| Step | Merge | Distance | Clusters after merge |
|---|---|---|---|
| 1 | B(5,6) + E(6,6) | 1.00 | {B,E}, A, C, D, F, G |
| 2 | {B,E} + C(6,5) | 1.00 (C–E) | {B,C,E}, A, D, F, G |
| 3 | {B,C,E} + F(7,7) | 1.41 (E–F) | {B,C,E,F}, A, D, G |
| 4 | {B,C,E,F} + D(5,8) | 2.00 (B–D) | {B,C,D,E,F}, A, G |
| 5 | {B,C,D,E,F} + G(2,8) | 3.00 (D–G) | {B,C,D,E,F,G}, A |
| 6 | + A(2,4) | 3.61 (A–B) | one cluster |
The dendrogram is built from these merge heights. Cutting it at a height between 3.0 and 3.6 gives two clusters: {A(2,4)} and the rest; cutting between 2.0 and 3.0 gives three clusters: {B,C,D,E,F}, {G} and {A}. (With complete linkage the last merges differ: {D,G} join at 3.0 and the final two clusters are {A,D,G} and {B,C,E,F}.) Steps were checked in Python.
Q4 – FP-Growth
FP-Growth (Han et al.) finds frequent itemsets without candidate generation. It scans the database only twice:
- First scan: count each item’s support, remove infrequent items and sort the frequent items in descending order of support (F-list).
- Second scan: insert each transaction (items in F-list order) into an FP-tree – a prefix tree where shared prefixes share nodes and each node keeps a count. A header table links all nodes of the same item.
- Mining: for each item (from the bottom of the header table) build its conditional pattern base (prefix paths), construct a conditional FP-tree, and recursively generate frequent patterns ending with that item.
Example (min support 2): T1 {a,b}, T2 {b,c,d}, T3 {a,c,d,e}, T4 {a,d,e}, T5 {a,b,c}. Supports: a 4, b 3, c 3, d 3, e 2 → F-list a, b, c, d, e. Inserting the transactions gives the paths a:4 → b:2 → c:1; a → c:1 → d:1 → e:1; a → d:1 → e:1; and a separate path b:1 → c:1 → d:1. For item e the conditional pattern base is {a,c,d:1}, {a,d:1} → frequent: {a,e}:2, {d,e}:2, {a,d,e}:2.
Advantages: no candidate generation, only two scans, compact tree; faster than Apriori on dense data. Limitation: the tree may not fit in memory for very large or sparse data.
Q5 – Naïve Bayesian classification
A probabilistic classifier based on Bayes’ theorem with the “naïve” assumption that attributes are conditionally independent given the class.
P(C | X) = P(X | C) · P(C) / P(X)
P(X | C) = P(x1 | C) · P(x2 | C) · … · P(xn | C)
Predict the class C that maximises P(X | C)·P(C)Steps: compute prior P(C) for each class from training data; compute likelihoods P(xᵢ | C) for each attribute value (for continuous attributes use a Gaussian distribution); for a new record multiply the likelihoods and prior for each class and choose the largest.
Example (golf data, 9 yes / 5 no): for X = (sunny, cool, high, windy=TRUE): P(yes)·P(sunny|yes)·P(cool|yes)·P(high|yes)·P(true|yes) = 9/14 × 2/9 × 3/9 × 3/9 × 3/9 ≈ 0.0053; P(no)·… = 5/14 × 3/5 × 1/5 × 4/5 × 3/5 ≈ 0.0206 → class no.
Zero-frequency problem: if a count is 0 the whole product becomes 0; Laplace correction (add 1 to each count) solves it. Advantages: simple, fast, works well with large data and text (spam filtering). Disadvantage: the independence assumption is often not true.
Q6 – Data preprocessing techniques
- Data cleaning: fill missing values (ignore tuple, use mean/median, most probable value), smooth noisy data (binning, regression, clustering), remove outliers and correct inconsistencies.
- Data integration: combine data from multiple sources; resolve schema conflicts, entity identification (cust_id vs customer_no) and redundancy (detected by correlation analysis, χ² test).
- Data transformation: normalisation (min-max: v′ = (v − min)/(max − min); z-score: v′ = (v − μ)/σ; decimal scaling), aggregation, generalisation (street → city), attribute construction.
- Data reduction: dimensionality reduction (PCA, wavelet transform, attribute subset selection), numerosity reduction (sampling, histograms, clustering), data compression.
- Discretisation: convert continuous values into intervals or concept hierarchies (age → young, middle, senior) using binning or entropy-based methods.
Preprocessing improves accuracy, completeness and consistency of data and makes mining faster.
