Data Mining Lab
Clustering, association rules, decision trees and anomaly detection.
- 3lessons
- 4experiments
- 5terms
Scientific introduction
Data mining discovers patterns in large data: similar groups, co-occurrence relations, classification rules and anomalies. Checking that a pattern is neither chance nor leakage is part of the work.
Learning objectives
- Run k-means and interpret and evaluate (silhouette) the result
- Mine association rules and understand support, confidence and lift
- Grow a decision tree, read its rules and watch for overfitting
- Detect anomalies with statistical methods
Topics
- Clustering
- Association rules
- Trees
- Anomalies
Core concepts
- Clustering
- Grouping similar observations without predefined labels.
- Silhouette coefficient
- A measure from -1 to 1 of cluster cohesion and separation.
- Support, confidence and lift
- Measures of an association rule: frequency, conditional probability of the consequent, and comparison with independence.
- Gini impurity
- A measure of class mixing in a node: one minus the sum of squared class proportions.
- Overfitting
- A model memorising training details so it performs worse on new data.
Theory
Clustering with k-means
The algorithm
Choose k centres, assign each point to the nearest, recompute centres as means, and repeat until stable. It minimises the within-cluster sum of squares. k-means++ improves the choice of initial centres.
Choosing k
Use the elbow curve and the silhouette coefficient (between -1 and 1). Scale features first. The method assumes roughly spherical, similar-sized clusters and can fail on irregular shapes.
Association rules
Measures
For a rule A → B: support = share of transactions containing both; confidence = P(B|A); lift = confidence ÷ P(B). Lift above 1 means more co-occurrence than independence predicts.
Apriori uses the property that every subset of a frequent itemset is also frequent to prune the search. Co-occurrence is not causation, and many rules are worthless.
Decision trees and anomaly detection
Trees
A CART tree splits data recursively and binarily by reducing Gini impurity (1 - Σp²). A deep tree memorises training data and overfits; limit depth or prune and measure on test data.
Anomalies
Simple statistical methods (z, IQR) suit a single variable. For many dimensions use distance, isolation or model-based methods. An "anomaly" may be an error or an important event: decide after inspection, not automatically.
Worked examples
A high-confidence rule can be useless
A rule "bread → water" with 90% confidence is worthless if 90% of everyone buys water; that is why we read lift, not confidence alone.
Interactive experiments
k-means simulator
Learning goal: Follow assignment and centre-update steps and evaluate silhouette.
Explanation and scientific documentation
The algorithm is run step by step on two features so you see the centres move.
Data: Synthetic data generated in your browser with an editable seed; the relationships are planted on purpose for learning and are not real data.
Objective J = Σ‖x − μ‖²; it decreases at each step and stops at convergence.
Limits: Depends on initial centres and may settle in a local optimum.
Association rules
Learning goal: Mine rules from synthetic baskets and read support, confidence and lift.
Explanation and scientific documentation
You set support and confidence thresholds and Apriori is really run on generated transactions with planted patterns.
Data: Synthetic data generated in your browser with an editable seed; the relationships are planted on purpose for learning and are not real data.
Lift = confidence ÷ consequent support; below 1 means weaker than independence.
Limits: The patterns are planted on purpose; real rules are weaker and noisier.
Decision tree
Learning goal: See the tree's splits and the effect of depth on training and test accuracy.
Explanation and scientific documentation
A CART tree is trained on synthetic customers to predict churn, showing its rules, train and test accuracy and the majority baseline.
Data: Synthetic data generated in your browser with an editable seed; the relationships are planted on purpose for learning and are not real data.
Gini G = 1 − Σp²; the chosen split minimises weighted impurity.
Limits: Accuracy alone misleads with imbalanced classes; compare with the baseline.
Anomaly detection
Learning goal: Compare k-NN distance, per-axis Z-score and density-based detection.
Explanation and scientific documentation
Known anomalies are injected and each method's catch rate and false alarms are computed.
Data: Synthetic data generated in your browser with an editable seed; the relationships are planted on purpose for learning and are not real data.
The trade-off between sensitivity and false alarms changes with the threshold.
Limits: Anomalies are planted; in reality labels are unknown.
Related algorithms and methods
k-means
Partitions observations into k groups by minimising squared distances.
Apriori
Generates frequent itemsets level by level.
CART
A decision tree with binary splits by Gini impurity.
Suitable datasets
- Customers (synthetic) Synthetic, generated in the browser
- Iris Link not verified yet
- Wine Link not verified yet
Practical projects
- Customer segmentation with k-means Intermediate
- Customer churn classification Intermediate
- Market basket analysis Intermediate
- Sensor anomaly detection Advanced
Assessment questions
Sources and references
- MacQueen, J. (1967). Some methods for classification and analysis of multivariate observations. Proceedings of the Fifth Berkeley Symposium on Mathematical Statistics and Probability, 1, 281-297 (bibliographic data entered by the editor, not machine-checked)
- Arthur, D., & Vassilvitskii, S. (2007). k-means++: the advantages of careful seeding. Proceedings of the 18th ACM-SIAM Symposium on Discrete Algorithms (SODA), 1027-1035 (bibliographic data entered by the editor, not machine-checked)
- Agrawal, R., & Srikant, R. (1994). Fast algorithms for mining association rules. Proceedings of the 20th International Conference on Very Large Data Bases (VLDB), 487-499 (bibliographic data entered by the editor, not machine-checked)
- Breiman, L., Friedman, J., Olshen, R., & Stone, C. (1984). Classification and Regression Trees. Wadsworth (bibliographic data entered by the editor, not machine-checked)
- Chandola, V., Banerjee, A., & Kumar, V. (2009). Anomaly detection: a survey. ACM Computing Surveys, 41(3), Article 15 DOI (bibliographic data entered by the editor, not machine-checked)
