S2 2026 · Side 1 of 2
Definitions · rules · formulas
about COMP20008
01 · Exam map course.json · brief
Continuous / project assessment — 50% · End-of-semester examination — 50%.
Permitted materials: not confirmed for this offering in the course materials we hold — check the exam instructions on the LMS.
| Rewarded move | Write in this order |
|---|---|
| Calculate | formula → substitution → answer → meaning |
| Compare | axis → A → B → consequence |
| Critique | failure cause → symptom → mitigation |
02 · Pipeline + types C01
| Test | Class | Examples |
|---|---|---|
| Arithmetic meaningful? | Numerical | temperature, income; discrete counts / continuous range |
| Label or identifier? | Non-numerical | postcode, phone number |
| Ordered category? | Could-be-either | S/M/L; code 1/2/3 if justified |
Do not classify by appearance. “3010” is non-numerical when it is a postcode. Separate this from dataset structure: table = structured; keys/tags = semi-structured (JSON/XML/HTML); free text/images = unstructured.
Privacy decision rule
| Release risk | Rule |
|---|---|
| re-identification by quasi-identifiers | k-anonymity: every pattern matches ≥k records |
| one sensitive value throughout a k-group | homogeneity attack → require ≥l distinct values |
| query answer reveals one person | global DP: add noise scaled to sensitivity |
03 · Clean before model C02
| If you see… | Do / say |
|---|---|
| rare, apparently random missingness | drop a few rows; loss is small |
| many/predictable missing values | impute: mean/median/mode, fill, regression or k-NN; may bias and dampen variance |
| mixed dates/names | standardise representation; de-duplicate |
| extreme value | verify; cap/remove or use robust method; never delete silently |
z-score: z = (x − x̄)/s → mean 0, SD 1
Min-max is bounded but one extreme stretches the range and compresses the rest. z-score uses standard-deviation units and is less squashed by an extreme. Scaling prevents units with a large numeric range from dominating distance/variance.
Sampling
Random: every record equally likely. Stratified: sample inside groups to preserve proportions. Systematic: every kth record. Always ask whether the scheme is representative; saving cost is not worth selection bias.
Ground an LLM answer
Why: an LLM predicts plausible tokens rather than checking facts; retrieval grounds output and reduces hallucination. Content partitioning: chunk for relevance and enforce permissions so one user’s data cannot enter another answer. AUTOMAT: Act-as, User, Targeted-action, Output, Mode, Atypical cases, Topic.
Trap “Impute” is incomplete: name the method and the bias ↔ information-loss trade-off.
04 · Capture → clean text C03–04
| Axis | Crawling | Scraping |
|---|---|---|
| Goal | coverage/indexing | structured data |
| Move | frontier; breadth-first links | targeted DOM parsing |
| Output | URLs/raw pages | field table |
| Control | robots.txt + visited set | find_all() + get_text() |
Flawed crawler: no visited set means duplicates re-enter the frontier, cycles repeat, unique coverage stalls and termination fails. Deduplicate before enqueue/fetch; stop at the target count of unique URLs.
| Lemmatise | Stem |
|---|---|
| dictionary + grammar; valid base: better→good | suffix rule; may be non-word: studies→studi |
Splitting needs exceptions for abbreviations and decimals. Lowercase/strip punctuation to merge forms. Lemmatisation shrinks sparsity; stop-word removal drops ubiquitous noise; n-grams restore short local order but enlarge vocabulary.
| Failure symptom | Diagnosis → repair |
|---|---|
| “Dr. Lee” becomes two sentences | naive full-stop split → add abbreviation/number exceptions |
| “The”, “the”, “the,” become three features | missing normalisation → lowercase + strip punctuation |
| chase/chased/chasing stay separate | surface forms → lemmatise to one dictionary form |
| crawler revisits navigation forever | no visited set → check before enqueue and fetch |
Answer shape Name the stage, show its input→output, then state the downstream benefit.
05 · Vectorise + visualise C05
BoW counts terms over a fixed vocabulary. It is simple, interpretable, fixed-length and language-agnostic; it also discards order/semantics, is sparse/high-dimensional and lets common terms dominate.
TF-IDF(t,d) = TF(t,d) × IDF(t)
IDF(t) = log(N/df(t))
| Use | Rule | Failure |
|---|---|---|
| raw TF | frequency within document | ubiquitous words swamp topics |
| TF-IDF | down-weight high df; up-weight distinctive terms | still sparse; still loses order |
| n-grams | retain short phrases | larger vocabulary |
Chart decision
| categories | bar | time/order | line |
| 2 numeric | scatter | distribution/groups | boxplot |
| matrix | heatmap | — | — |
Representation diagnosis
| Need | Representation | Reason |
|---|---|---|
| interpretable counts | BoW | fixed coordinates; easy distance |
| topic distinction | TF-IDF | distinctive terms outweigh ubiquitous ones |
| short phrase/order | n-grams | retain local sequence, but expand vocabulary |
| word context | windowed co-occurrence | count neighbours around each target occurrence |
For a critique, separate representation loss (order/semantics discarded) from weighting failure (common terms dominate) and match the fix to the failure.
06 · Cluster + reduce C06–08
SSE = Σclusters Σpoints ‖x − μcluster‖²
Elbow: plot SSE against k; pick the bend where marginal reduction collapses. Advantage: simple/visual. Limitation: bend may be ambiguous/subjective; silhouette or Calinski–Harabasz are alternatives. Outlier: squared distance inflates SSE and drags a centroid or consumes a cluster. Remove/cap after verification, scale, or use k-medoids/density methods.
| Method | Cluster distance / choice | Signature |
|---|---|---|
| k-means | nearest mean; set k first | flat; outlier-sensitive |
| single link | minimum pair distance | chaining |
| complete link | maximum pair distance | compact |
| average link | mean pair distance | compromise |
| VAT | reordered distance matrix | dark diagonal blocks suggest k |
PCA
Project onto orthogonal directions of maximum variance: PC1 most, PC2 next. Variance ≠ target relevance. A low-variance direction may separate classes; scale first because PCA is variance-sensitive.
Compare clusterings
Treat each clustering as a categorical labelling and compute NMI: near 1 means the labellings agree; near 0 means they disagree. It compares partitions even when cluster names differ. Do not confuse this use with VAT, which diagnoses cluster tendency before fitting.
07 · Dependence → prediction C08–12
MI(X,Y) = H(Y) − H(Y|X)
NMI = MI/min(H(X),H(Y))
Pearson r ∈ [−1,1]: signed linear association; misses curved/non-monotone structure. MI: 0 iff independent; detects non-linear/categorical dependence, but has no sign and continuous data needs discretisation. Entropy is 0 when deterministic; binary entropy is 1 bit at 50/50.
| Stem | Choose / warning |
|---|---|
| predict class from labelled rows | classification: k-NN/tree |
| predict continuous value | regression: ŷ=b₀+b₁x; least squares |
| small local neighbourhood | k-NN; scale; k small noisy, k large smooth |
| interpretable recursive rules | tree; depth controls overfit |
| near-unique category | information gain biased to high cardinality → pure leaves, memorisation |
Precision=TP/(TP+FP)
Recall=TP/(TP+FN)
F1=2PR/(P+R)
Metric by error cost: false negative costly (fraud/cancer) → recall; false positive costly → precision. Accuracy can hide failure on imbalanced data. k-fold CV rotates the held-out fold and averages scores; every row is tested once.
Leakage: target or future-only data appears among features; “perfect” training MSE can be invalid because the value is unavailable at prediction. Audit availability before fitting.
Feature selection: filter methods rank features (correlation/MI), wrapper methods search subsets by model performance, and embedded methods select during fitting. Verification: public key → recompute statement hash → compare with signed hash; a blockchain edit changes a hash and breaks later links.