IB COMPUTER SCIENCE | A4

MACHINE LEARNING REVISION

Connect learning tasks, hardware, preprocessing, algorithms and ethics. Reconstruct worked examples, filter SL/HL material and select cards for your revision list.

Selections are retained, including cards hidden by filters. All selected cards remain in your revision list.

YOUR A4 REVISION ROUTE

Connect the topic as a process: identify a learning task, match its hardware and data preparation, explain how suitable approaches work, then compare performance and evaluate ethical implications.

Common SL/HL content is A4.1 and A4.4. All of A4.2 and A4.3 is HL-only. The level switch hides labelled HL notes and cards while retaining selections, including selected cards currently hidden by filters.

Use the worked examples actively before flipping cards. There are 306 cards: 72 common cards and 234 HL cards, with 18 for each syllabus objective. Filter by subsection or individual objective and build your personal revision list. Selections last while this page remains open.

A4.1.1 | TYPES OF MACHINE LEARNING

Supervised learning fits from examples paired with targets. A category such as spam/not spam is classification; a measured quantity such as duration is regression. Unsupervised learning discovers structure without known target labels guiding the fit, such as customer clusters or co-occurring products.

Reinforcement learning involves an agent choosing actions in an environment and learning from reward feedback toward greater expected cumulative return. It differs from both grouping a static dataset and receiving a correct action label for every situation.

Deep learning describes multi-layer neural-network modelling; transfer learning reuses a learned representation or model for a related task. These labels can overlap with learning settings rather than forming five exclusive boxes. Connect applications to outputs: sentiment classification, object detection, medical-image analysis or robot navigation need a defined task and evaluation.

A4.1.2 | HARDWARE AND DEPLOYMENT

Requirements follow the workload: model, input size, training versus inference, response time, request load and software compatibility. A standard CPU laptop can suit modest tabular work; suitable parallel numeric tasks may benefit from accelerators. A GPU is not compulsory for every ML project.

Distinguish system RAM and accelerator execution memory from persistent storage holding datasets, model files and checkpoints. Model weights alone do not include intermediate values or runtime state. Capacity determines what fits; bandwidth and the input pipeline affect how efficiently it runs.

ASICs specialise hardware; a TPU is a particular ML ASIC family. FPGAs have configurable logic. Edge describes processing near inputs, cloud describes provisioned remote infrastructure and HPC describes coordinated high-performance infrastructure. These are not exclusive alternatives: a cloud system can provide accelerators. Check power, heat, I/O, networks and scaling overhead.

A4.2.1 | DATA CLEANING AND SCALING HL ONLY

Poor features or labels teach misleading relationships. Remove confirmed repeat observations or consolidate matched records under source rules; equal feature values do not prove duplicate identity. Confirm units and category meanings before converting formats. Filter records outside the legitimate task rather than deleting difficult valid cases.

An outlier can be valid. Investigate source, units and context before retaining, correcting, capping or excluding it. Missing is not zero: deletion loses information and can bias coverage; imputation substitutes an estimate; predictive imputation uses other available attributes but can propagate error. Document what changed and preserve raw data.

Here normalization means min–max scaling, (x−min)/(max−min), while standardization means (x−mean)/standard deviation. Fit statistics on training data only and apply them unchanged to held-out and future data. Future min–max values can exceed 0–1, standardization does not enforce a normal distribution and constant features need explicit handling.

A4.2.2 | FEATURE SELECTION HL ONLY

Selection retains informative original input attributes. An irrelevant feature adds no useful evidence; a redundant feature repeats information already available. Selection can reduce collection cost, computation and accidental fitting, but discarding useful inputs can harm generalisation.

Filter methods screen using data criteria such as variation or suitable association tests. Wrappers fit and evaluate a chosen model on candidate subsets, such as forward selection. Embedded methods obtain selection evidence within training, such as L1-induced zero coefficients or tree-derived importance. Each has model, cost or interaction limitations.

A feature weak alone can be useful in combination, as in XOR. Greedy wrappers do not guarantee finding the global best subset either. Exclude outcome shortcuts unavailable at prediction time, fit selection inside training folds and keep final test data outside subset choices. Association and importance are not causal proof.

A4.2.3 | DIMENSIONALITY REDUCTION HL ONLY

An input dimension is a coordinate in the model representation. Removing columns reduces dimensionality; deleting rows reduces the number of examples. Selection keeps some original inputs; extraction constructs fewer transformed coordinates. The aim is a smaller representation preserving relevant information.

The curse of dimensionality can involve sparse coverage, more sample needs, weak distance contrast, overfitting, computation and memory. Sparse coverage is not the same as a mostly-zero matrix. Irrelevant varying coordinates can overwhelm useful distances. The effects depend on structure and algorithms, not a universal maximum number of features.

Reduction can aid visualisation and efficiency but lose rare or predictive distinctions. A clear 2D plot does not prove that original relationships survived. Fit learned reductions within training and validate the complete pipeline. PCA and LDA statistical techniques are beyond this syllabus; prioritise purpose, consequences and trade-offs.

A4.3.1 | LINEAR REGRESSION HL ONLY

For one predictor, ŷ=mx+b estimates a continuous response. x is the independent predictor, observed y is the dependent response and ŷ is the prediction. Slope m is predicted change per input unit; intercept b is the prediction at zero input, which may lie outside meaningful observed conditions.

Ordinary least squares chooses parameters to minimise training summed squared residuals. A residual is y−ŷ: negative means the prediction is too high. Squaring avoids cancellation. A fitted line need not pass through every point and a fitted association does not establish causation.

R²=1−SSE/SST compares squared error with squared variation around the evaluated outcomes’ mean. It can be negative and is undefined under the ordinary formula when SST=0. It is not percentage exactly correct. Check useful-unit errors, independent performance and whether a new input is interpolation or extrapolation.

A4.3.2 | K-NN AND DECISION TREES HL ONLY

Classification outputs a discrete category even when features or category codes are numeric. K-NN represents a query, computes distances to retained labelled examples, selects k neighbours and combines their labels. With equal voting, the most common label wins. Scale, irrelevant dimensions and k affect the neighbourhood.

Odd k avoids a two-class equal-vote tie but not equal-distance cutoff ties or every multiclass tie. A unanimous neighbourhood is not certainty. Collaborative filtering uses neighbour preference patterns for recommendations and can involve ratings or rankings rather than only category voting.

A tree follows learned feature tests from root through matching branches to a leaf. Labelled training data guide useful splits; deeper detail can overfit and pruning or validated limits can help. Trace exact comparisons, including equality. Medical decision support needs appropriate qualified assessment; a predicted diagnostic class is not proof.

A4.3.3 | HYPERPARAMETER TUNING AND METRICS HL ONLY

Hyperparameters such as k or maximum depth configure behaviour; parameters such as coefficients or fitted thresholds are learned during training. Tune on development validation, using consistent cases or appropriate folds and a declared metric. Keep final test data outside all these choices.

With a named positive class, accuracy=(TP+TN)/total, precision=TP/(TP+FP), recall=TP/(TP+FN), and F1=2TP/(2TP+FP+FN). Precision concerns predicted positives; recall concerns actual positives. Imbalance can give high accuracy while detecting no rare positives. F1 does not use TN directly or encode every error cost.

Underfitting misses useful structure; overfitting captures sample-specific detail. Investigate training and validation patterns rather than assigning a cause from one weak score. Grid or random search consumes evaluation budget and can overuse validation. Fit preprocessing inside folds, report zero-denominator conventions and refit the chosen pipeline before independent final evaluation.

A4.3.4 | UNSUPERVISED CLUSTERING HL ONLY

Clustering groups observations using feature similarity without known target-group labels guiding the fit. For purchasing segments, define comparable behaviour features and a consistent time window. IDs are for record management, not normally meaningful numeric similarity.

K-means chooses k initial centres, assigns observations to nearest centres, recomputes coordinate means and repeats to a stopping rule. Inertia is the within-cluster squared-distance sum. More clusters can lower this sum without creating useful segments. Initialisation, scaling, outliers and group shapes matter.

Centroids need not be observed people, and cluster numbers have no fixed semantic meaning. Hierarchical approaches build nested groups; density-based approaches can leave noise unassigned. Evaluate stability, structure and practical usefulness. Assigning a new point to fitted centres does not itself refit them; a returned partition is not evidence of permanent human types.

A4.3.5 | ASSOCIATION RULES HL ONLY

Define a transaction, then encode item presence and find frequent itemsets. A rule X→Y relates co-occurrence, with a nonempty antecedent X and non-overlapping consequent Y. The arrow is neither a causal guarantee nor purchase order.

Support=count(X and Y)/all transactions; confidence=count(X and Y)/count(X); lift=confidence/support(Y). Reversal keeps joint support and lift for nonzero supports but can change confidence. High confidence can merely reflect a common consequent; tiny support can make an apparently strong rule unstable.

Apriori uses the fact that a frequent itemset’s subsets must meet the same support threshold. Pruning helps control growing combinations. In crime analysis, a recorded area-week association between vandalism and theft is not individual guilt or causation. Inspect exposure, reporting, shared influences, feedback and independent repeatability.

A4.3.6 | REINFORCEMENT LEARNING HL ONLY

The agent observes its situation, chooses an action under a policy and receives reward and a next observation from the environment. Experience updates estimates or policy behaviour. The goal is expected cumulative reward, not always the largest immediate reward.

Exploration gathers information about alternatives; exploitation uses the currently preferred choice. Epsilon-greedy chooses a random-action branch with probability ε and a greedy branch otherwise. A random action can match the greedy action. Delayed reward creates a credit-assignment problem.

In the toy route, Direct gives 2 while Corridor then Finish gives −1+8=7 raw return, or 6.2 with discount 0.9. A reset position can retain learning; resetting the learner clears it. Evaluate a policy separately from exploratory training. Reward design can encourage loopholes, and simulator success does not prove physical reliability.

A4.3.7 | GENETIC ALGORITHMS HL ONLY

A genetic algorithm searches a population of complete encoded candidates. For a travelling salesperson tour, a chromosome is a stop permutation with the fixed depot added at both ends. Validity means every required stop appears once and the full return route is included.

Evaluate an objective or fitness with an explicit better direction, select parents, create children through representation-compatible crossover and mutation, evaluate the next population and repeat. Tournament selection samples candidates; prefix-order crossover and swaps can preserve route permutations.

Elitism can protect the best deterministic score while the population average still worsens. Variation does not guarantee a better child. Termination by budget, target or plateau does not prove global optimality. Timetabling, design and scheduling require task-specific encodings, constraints and evaluation; repeated runs and fair budgets matter.

A4.3.8 | ANNS AND MULTI-LAYER NETWORKS HL ONLY

A unit computes z=Σwx+b then a=f(z). Weights multiply inputs, bias shifts the sum and activation produces an output. A classic perceptron uses a threshold; modern hidden units often pass continuous nonlinear activations such as ReLU.

An MLP has input, hidden and output layers. Hidden activations become inputs to later units. Nonlinear hidden transformations enable patterns beyond one affine boundary; stacking affine stages alone remains affine. The configured XOR example demonstrates representation, not training.

Forward propagation calculates outputs. Supervised training measures loss and adjusts weights/biases, commonly using backpropagation and an optimiser. Output activation depends on task: numerical regression, binary score or mutually exclusive class vector. Deeper networks and high scores are not guarantees of generalisation.

A4.3.9 | CNNS AND SPATIAL HIERARCHIES HL ONLY

Images retain height, width and channels. Shared kernels multiply and sum local patches to produce feature maps; activation introduces nonlinearity. Standard filters combine input channels and each produces an output channel. Kernel size is not filter count.

Stride changes sampling positions; padding changes border treatment and dimensions. Pooling summarises local responses, usually per channel, and has no ordinary learned kernel weights. Later layers combine earlier responses over broader receptive fields, allowing learned spatial hierarchies rather than a guaranteed edge/part label per layer.

A classification head can flatten or pool representations then use learned output computations. Loss and training adapt filters and later parameters. Layer count, kernel size, stride, activation and loss affect cost and behaviour. Fixed teaching filters illustrate forward calculation only; spatial architecture does not itself establish reliability.

A4.3.10 | MODEL SELECTION AND COMPARISON HL ONLY

Different methods can perform differently as task, sample size, scale, noise and relationships change. Define the required output first. A baseline gives comparative context; evaluate candidate-appropriate whole pipelines using comparable held-out cases and transparent tuning budgets.

Choose metrics and constraints from actual consequences. Equal accuracy can hide different FP/FN patterns. Cost weights, memory, latency and explanation needs can change the preferred model; if none qualifies, report that rather than inventing a winner.

Keep family, preprocessing, features, thresholds and hyperparameters inside development decisions. Preserve independent final evaluation. Small score gaps can be unstable, and explainability is not causal proof or a fairness certificate. Record reasons and limitations, then monitor changed conditions in deployment.

A4.4.1 | ETHICS OF MACHINE LEARNING

Discuss a contextual benefit, a mechanism of harm, affected stakeholders, possible responses and their limits, then a justified conclusion. Accountability requires answerable people and real remedies; transparency and explanation support challenge without proving correctness.

Bias can arise in representation, measurement, labels, proxies and feedback. Fairness is not one universal metric. Consent must be meaningful in context; privacy includes appropriate inference and use, while security protects against unauthorised access, alteration or disruption. Removing names or adding a checkbox does not settle the issue.

Online communication can benefit from accessibility and moderation while raising misinformation, harassment, anonymity and privacy trade-offs. Societal and environmental effects include distribution, work, resource use and scale. Human oversight needs evidence, time and power to change decisions, not merely a signature.

A4.4.2 | TECHNOLOGY IN DAILY LIFE

AR overlays digital information on a physical-world view; VR commonly provides an immersive digital environment. Both can expand access to learning or assistance while creating bystander privacy, accessibility and data-use concerns. Equipment provision alone is not equitable participation.

Pervasive AI can operate across background services. Assistance differs from authority to send, purchase or restrict access. Integration can create dependence, so consider autonomy, resilience and practical alternatives. Quantum computing may support certain tasks; sufficiently capable future systems could threaten some public-key schemes, not all encryption today.

Core ethical values remain relevant while capability, scale, linkage, authority and populations change. Reassess purposes and safeguards rather than automatically extending old consent or approval. Discuss society, rights, privacy and equity with conditional conclusions; post-quantum algorithms can operate on conventional computers and future-risk claims need uncertainty.

WORKED | MATCH THE HARDWARE TO THE WORKLOAD

Scenario Possible configuration Why and limit
Small tabular classroom model CPU laptop with sufficient RAM and storage May fit well without a GPU; measure real workload.
Battery-powered local vision Compatible edge processor/accelerator, sensor I/O and working memory Response, power and heat matter; training may occur elsewhere.
Large coordinated training Compute/accelerators, memory, storage pipeline and interconnects Communication and input bottlenecks can limit scaling.

Ten million four-byte parameters use 40,000,000 raw bytes, about 38.15 MiB, before runtime/intermediate state. Extra SSD space is not automatically accelerator execution memory.

WORKED | SCALING AND SPARSE COVERAGE HL ONLY

Training values 2,4,4,6 have min 2, max 6, mean 4 and population standard deviation √2. For x=6, min–max scaling gives (6−2)/(6−2)=1; standardization gives (6−4)/√2≈1.414. A later x=10 transforms to 2 under the fitted min–max rule.

With five bins per dimension, six dimensions give 5⁶=15,625 cells. One thousand examples average 0.064 per cell in this simplified grid. This is not a universal required sample-size formula. Dense raw input storage instead grows as examples × dimensions × bytes per value.

WORKED | LINEAR REGRESSION AND FIT HL ONLY

x Observed y Predicted 2.4x+3.8 Residual
1 7 6.2 0.8
2 8 8.6 -0.6
3 11 11 0
4 12 13.4 -1.4
5 17 15.8 1.2

At x=4.5 the prediction is 14.6. Squared residuals sum to 4.4; squared deviations from mean y=11 sum to 62. R²=1−4.4/62≈0.929. MAE=(0.8+0.6+0+1.4+1.2)/5=0.8 minutes. These are teaching/training results, not an independent test. Seven kilometres is outside the observed 1–5 km range.

WORKED | CLASSIFICATION METRICS AND CHOICE HL ONLY

Actual ↓ / Predicted → Defective + Good −
Defective + TP=16 FN=4
Good − FP=8 TN=72

Accuracy=88/100=88%; precision=16/24≈66.7%; recall=16/20=80%; F1=32/44≈72.7%. If there are no predicted positives, precision’s ordinary formula is undefined. Naming the positive class and axis conventions prevents denominator errors.

A separate supplied model comparison has a tree with FP 10/FN 10 and ANN with FP 12/FN 4. If FP costs 10 and FN costs 1, costs are 110 and 124: the tree can win under that objective despite lower F1. Apply actual hard requirements first; no eligible candidate is an honest result.

WORKED | GROUPS AND CO-OCCURRENCES HL ONLY

K-means updates a group containing (2,1),(8,2),(8,3),(9,2) to mean (6.75,2). Reassignment can then move a point to another centroid. A cluster number is an arbitrary identifier, not a provided class or permanent human type.

Association example Support Confidence Lift
Bread→Milk: 10 baskets, Bread5, Milk6, joint4 4/10=40% 4/5=80% 0.8/0.6≈1.333
Reverse Milk→Bread 40% 4/6≈66.7% Same 1.333

For 100 area-weeks with vandalism 20, theft 30 and joint 12, support is 12%, confidence 60% and lift 2. This is recorded area-level co-occurrence, not causation, sequence or individual guilt. Check collection and reporting.

WORKED | SEQUENTIAL REWARD AND POPULATION SEARCH HL ONLY

In the RL toy task, Start→Corridor gives −1 and Corridor→Goal gives +8, so raw return is 7. Discounted return at γ=0.9 is −1+0.9×8=6.2, better than immediate Direct reward 2. Exploration can reveal the delayed route; exploitation alone can preserve incomplete knowledge.

For a genetic route search, prefix AB from ABCDEF plus unused stops in D A F C B E order gives ABDFCE. Swapping positions 3 and 5 gives ABCFDE. Evaluate the complete closed tour. Population replacement and elitism concern candidate generations, not an RL state–action update.

WORKED | NEURON, XOR AND CNN HL ONLY

A unit with x=(2,1), w=(0.6,−0.4), b=−0.3 has z=0.5. Step with z≥0 gives 1, ReLU gives 0.5 and sigmoid approximately 0.622. Activation and loss have different roles.

Configured XOR: h₁=step(x₁+x₂−0.5), h₂=step(x₁+x₂−1.5), output=step(h₁−2h₂−0.5). For (1,1), hidden values are both 1 but output is 0. This is a forward demonstration with supplied weights, not evidence of training.

For convolution, spatial size=floor((N+2P−K)/S)+1 with dilation 1. A 5×5 input, 3×3 kernel, stride 2, padding 0 gives 2×2 per filter. Eight 3×3 filters over RGB with a bias each have (27+1)×8=224 learned parameters. Pooling and flattening do not themselves learn those weights.

WORKED | BUILD A DISCUSS ANSWER

Use context → benefit → mechanism of concern → stakeholder effect → response and its limit → conditional judgement. Do not merely name privacy or fairness.

Example: a support model could improve timely access. However, historical referral labels may overlook some students. Meaningful review and group-error checks can help if staff have time and override authority. A limited trial may be justified only with necessary data, practical correction and evidence of benefit over the current process.

AR translation approval does not automatically cover later facial identification. A VR device loan count does not prove accessibility. Future quantum-related confidentiality risks need careful scheme-specific reasoning, not claims that all encryption is broken. Explain why new capability, scale or authority requires reassessment.

COMMON MISTAKES | SL & HL

Avoid Replace with
ML always needs a GPU Hardware follows processing, memory, storage, compatibility and deployment needs.
Deep/transfer are exclusive alternatives to supervised learning These describe other dimensions and can overlap.
Remove a sensitive attribute and fairness is solved Proxies, labels, coverage and consequences still matter.
A notice, checkbox or human signature settles ethics Test meaningful choice, oversight, authority, remedies and proportionality.
VR is AR, or virtual means no physical impact Distinguish the interfaces and consider lifecycle resources.
Ethical guidelines expire whenever technology improves Core values remain; revisit their application and evidence.

COMMON MISTAKES | HL APPROACHES HL ONLY

Avoid Replace with
All outliers are errors; missing is zero Investigate source and context; justify a missingness policy.
Reduction always improves accuracy Preserve relevant distinctions and validate the whole pipeline.
R² is percentage exactly correct It compares squared residuals with evaluated mean-reference variation.
Odd k removes every tie Distance cutoffs and multiclass votes still need policies.
High confidence proves causation Compare support and baseline, and validate co-occurrence.
A moving agent or preset XOR is automatically training Inspect what estimates or parameters actually change.
Every GA child improves; convergence proves optimality Variation can worsen candidates; stopping is not a global proof.
Kernel size equals filter count; pooling learns kernels Spatial window, output channels and reduction operations differ.

FINAL SELF-CHECK

Can you identify a task, justify its resources, explain an approach through a worked example and discuss consequences for people? HL students should also reconstruct preprocessing and algorithm calculations without confusing training evidence with independent evaluation.

Select weak flashcards, revisit their linked lessons and use the separate end-of-topic review for retrieval and written communication. The workbook is a distinct resource and is coming soon.