Lesson 1
Decision Trees for Classification
A decision tree classifies records by repeatedly splitting the data on attribute tests until the leaves are mostly one class. Splits are chosen to maximise purity, measured by Gini impurity or entropy and information gain. Pruning and depth limits stop overfitting.
Structure
- Root node: the first split on the whole dataset.
- Internal nodes: tests on an attribute (e.g. Age < 30?).
- Branches: the outcomes of a test.
- Leaf nodes: the predicted class, usually the majority class of the training records in that leaf.
- A new record is classified by following the tests from the root down to a leaf.
Choosing splits
- Greedy top-down recursive partitioning: at each node, pick the split that best separates the classes.
- Entropy = -sum p_i log2(p_i). It is 0 for a pure node and 1 for a 50/50 two-class node.
- Information gain = entropy(parent) - weighted average entropy(children).
- Gini impurity = 1 - sum p_i^2. Its maximum is 0.5 for two balanced classes.
- Splitting stops when nodes are pure, too small, or the maximum depth is reached.
Overfitting and pruning
- Deep trees memorise noise: high training accuracy but poor test accuracy.
- Pre-pruning limits depth, minimum samples per leaf, or minimum gain.
- Post-pruning grows the full tree, then cuts branches that do not improve validation performance.
- Pros: interpretable, handles mixed data types, needs no feature scaling.
- Cons: unstable (small data changes alter the tree) and prone to overfitting.
Key terms
- Leaf node
- A terminal node that assigns a class prediction.
- Entropy
- A measure of class impurity in a node: -sum p log2 p.
- Information gain
- The reduction in entropy achieved by a split.
- Gini impurity
- 1 - sum p_i^2; the probability of misclassifying a randomly labelled record.
- Pruning
- Removing branches to reduce overfitting.
Lesson 2
Logistic Regression Explained
Logistic regression predicts the probability of a binary outcome by passing a linear combination of predictors through the sigmoid function. Coefficients are estimated by maximum likelihood and act on the log-odds. A threshold (often 0.5) converts probabilities into class labels.
Model
- z = b0 + b1x1 + ... + bkxk
- p = 1/(1+e^(-z)), which is always between 0 and 1.
- Logit form: ln(p/(1-p)) = z, so the log-odds are linear in the predictors.
- At z = 0, p = 0.5.
Interpreting coefficients
- A one-unit increase in x_j changes the log-odds by b_j.
- The odds are multiplied by e^(b_j) (the odds ratio).
- A positive b means the probability increases with x; a negative b means it decreases.
Fitting and evaluation
- Fitted by maximum likelihood, equivalently minimising log loss (cross-entropy), not least squares.
- Classify as 1 if p >= threshold; changing the threshold trades sensitivity against specificity.
- Evaluate with a confusion matrix, accuracy, precision, recall, and ROC curve with AUC.
- Use it instead of linear regression for binary outcomes, because linear predictions can fall outside 0-1.
Key terms
- Sigmoid
- The function 1/(1+e^(-z)), which maps any real number to (0,1).
- Odds
- p/(1-p).
- Logit
- The log-odds, ln(p/(1-p)).
- Odds ratio
- e^b; the multiplicative change in odds per unit increase in x.
- Maximum likelihood
- The estimation method that chooses the parameters making the observed data most probable.
Lesson 3
K-Means Clustering
K-means is an unsupervised algorithm that partitions data into k clusters by alternately assigning points to the nearest centroid and recomputing centroids. It minimises the within-cluster sum of squares. The choice of k, feature scaling, and initialisation all strongly affect the results.
Algorithm
- 1. Choose k and initialise k centroids (randomly or with k-means++).
- 2. Assign each point to its nearest centroid, usually by Euclidean distance.
- 3. Recompute each centroid as the mean of its assigned points.
- 4. Repeat steps 2-3 until assignments stop changing.
- Objective: minimise WCSS = sum of squared distances from each point to its centroid.
Choosing k
- Elbow method: plot WCSS against k and pick the bend where improvement slows.
- Silhouette score: ranges from -1 to 1, and higher means better separated clusters.
- WCSS always decreases as k grows, so the smallest WCSS alone is not a valid way to choose k.
Practical issues
- Scale (standardise) features, because distance is dominated by large-scale variables.
- The algorithm converges to a local optimum, so run it with multiple initialisations.
- It assumes roughly spherical, similar-size clusters and is sensitive to outliers.
- It needs numeric data, because centroids are means.
Key terms
- Centroid
- The mean point of a cluster.
- WCSS / inertia
- The within-cluster sum of squared distances.
- Elbow method
- A heuristic that chooses k at the bend of the WCSS-versus-k curve.
- k-means++
- A smart initialisation that spreads out the initial centroids.
- Silhouette score
- A measure of how well each point fits its own cluster compared with the nearest other cluster.
Lesson 4
Association Rules: Support, Confidence and Lift
Association rules find items that frequently occur together in transactions, written as X -> Y (if X then Y). Support, confidence and lift measure how common, how reliable and how interesting a rule is.
Association rules
- A rule has the form X -> Y: X is the antecedent (left-hand side), Y is the consequent (right-hand side).
- Typical use is market basket analysis, e.g. {bread} -> {butter}.
- A rule shows co-occurrence, not causation.
Support and confidence
- Support(X) = transactions containing X / total transactions.
- Support(X -> Y) = P(X and Y) = transactions containing both / total transactions.
- Confidence(X -> Y) = Support(X and Y) / Support(X) = P(Y | X).
- Confidence is directional: Conf(X -> Y) usually differs from Conf(Y -> X).
Lift
- Lift(X -> Y) = Confidence(X -> Y) / Support(Y) = P(X and Y) / (P(X) x P(Y)).
- Lift > 1 means positive association: X makes Y more likely.
- Lift = 1 means X and Y are independent.
- Lift < 1 means negative association: X makes Y less likely.
- Lift is symmetric: Lift(X -> Y) = Lift(Y -> X).
Mining rules
- Set a minimum support and a minimum confidence threshold.
- The Apriori algorithm finds frequent itemsets using one fact: every subset of a frequent itemset must itself be frequent.
- Rules are then generated from the frequent itemsets and ranked, often by lift.
Key terms
- Support
- The share of all transactions that contain an itemset.
- Confidence
- The conditional probability of the consequent given the antecedent.
- Lift
- Confidence divided by the consequent's support; it measures association beyond chance.
- Antecedent
- The 'if' part of a rule.
- Consequent
- The 'then' part of a rule.
- Apriori
- An algorithm that finds frequent itemsets by pruning any itemset with an infrequent subset.
Lesson 5
Dashboard Design Principles
A dashboard is a visual display of the most important information needed to reach objectives, arranged on one screen so it can be monitored at a glance. Good design starts from the audience and purpose, then uses clear layout, suitable charts and minimal clutter.
Purpose and audience
- Know who will use the dashboard and which decisions it must support.
- Strategic dashboards show high-level KPIs for executives.
- Operational dashboards support real-time monitoring.
- Analytical dashboards allow exploration and drill-down.
- Show only KPIs that are relevant and actionable.
Layout and hierarchy
- Put the most important information at the top left, where reading starts.
- Group related metrics together.
- Keep the main view on a single screen and avoid scrolling.
- Use whitespace and consistent alignment.
Choosing visuals
- Line charts show trends over time.
- Bar charts compare categories.
- Use KPI cards or bullet graphs for targets.
- Avoid 3D effects, gauges that waste space, and overuse of pie charts.
- Give every chart context: a comparison to target, a prior period or a benchmark.
Clarity and usability
- Maximise the data-ink ratio by removing chartjunk.
- Use colour sparingly and consistently, e.g. to highlight alerts.
- Be accessible to colour-blind users; do not rely on red vs green alone.
- Use clear labels and units.
- Add interactivity such as filters and drill-down where useful.
- Iterate the design based on user feedback.
Key terms
- Dashboard
- A single-screen visual summary of key metrics for monitoring.
- KPI
- Key performance indicator: a metric tied to a business objective.
- Data-ink ratio
- The proportion of a graphic's ink that presents data; it should be maximised.
- Chartjunk
- Decorative elements that do not convey information.
- Drill-down
- Interaction that moves from summary data to more detail.
