Lesson 1 of 5

What machine learning is

Ordinary software follows rules that a person wrote: if the amount is over a limit, ask for approval. Machine learning (ML) works the other way round. Instead of writing the rules, you give the computer many examples, and it works out a rule that fits them. The result is called a model: a set of learned numbers that turns an input into an output, such as a score, a category or a forecast.

The idea is older than most people think. In 1959 Arthur Samuel, a researcher at IBM, published a study of a program that improved at the game of checkers by playing and learning from the results, until it could beat the person who had written it. His paper is widely credited with making the term "machine learning" popular.

A useful test for whether something is machine learning was set out by the computer scientist Tom Mitchell in 1997. In our words: a program learns if it gets better at a task, by a measure you can check, as it is given more experience. All three parts matter. If you cannot say what the task is, how you will measure it and what the experience (the data) is, you are not ready to build a model.

Where ML sits:

  • Artificial intelligence (AI) is the broad goal of machines doing tasks that normally need human judgement.
  • Machine learning is the main way AI is built today: learning from data rather than hand-written rules.
  • Deep learning is one family of machine learning that uses large neural networks. It powers image recognition and language models, and has its own courses in this series.

When ML is the right tool: when the pattern is real but too complex or changes too often to write down as rules, and when you have enough good examples. Spotting unusual card payments, sorting incoming documents, forecasting cash demand at branches and estimating crop yields from satellite images are typical. When it is not: when a clear rule already does the job, when the law requires a fixed rule, or when there is no reliable data. A simple rule you can explain beats a clever model you cannot trust.

Lesson 2 of 5

The main kinds of learning

Machine learning is usually divided by what the examples look like and what you want back.

Supervised learning learns from examples that come with the right answer, called a label. Past loan applications marked "repaid" or "defaulted", or emails marked "spam" or "not spam", are labelled data. There are two main jobs:

  • Classification predicts a category: fraud or genuine, which department a complaint should go to.
  • Regression predicts a number: next month's sales, the price a house is likely to fetch, how many minutes a delivery will take.

Unsupervised learning works with examples that have no labels, and looks for structure on its own:

  • Clustering groups similar examples, for example customers whose spending looks alike. A common method, k-means, places a chosen number of centre points and moves them until each sits in the middle of a group.
  • Anomaly detection finds examples unlike the rest, such as a transaction pattern no other account shows. Unusual is not the same as wrong; a person still has to look.
  • Dimensionality reduction squeezes many measurements into a few that keep most of the information, which helps with charts and with later modelling.

Reinforcement learning learns by trial and error. A program, called an agent, takes actions in an environment and receives a reward or penalty, and learns over time which actions lead to the most reward. Samuel's checkers player was an early ancestor. It suits games, robotics and some planning problems, and it was one of the steps used to tune today's language models.

A fourth term you will meet is self-supervised learning, where the labels come from the data itself: hide the next word of a sentence and ask the model to predict it. That trick is how large language models learn from huge amounts of text without anyone labelling it.

Choosing quickly:

  • Examples with known answers, and you want the answer for new cases: supervised.
  • Examples without answers, and you want groups, outliers or a simpler picture: unsupervised.
  • A way to act and a score for the result, and you want the strategy that earns the best score: reinforcement.
Lesson 3 of 5

Data, features and labels

Practitioners have a saying: the data matters more than the algorithm. A simple method on good data usually beats a sophisticated one on poor data.

Think of the data as a table. Each row is one example, such as one transaction. Each column that describes it is a feature: amount, time of day, merchant type, how long the account has been open. In supervised learning, one more column holds the label, the answer you want the model to learn.

Feature engineering is turning raw records into features that carry the signal. "Amount" on its own says little. "Amount compared with this customer's usual spending" or "number of payments in the last hour" can say a great deal. This step often needs people who know the business more than people who know the mathematics.

Five questions to ask of any data set:

  • Is it accurate? Typing errors, duplicates and missing values are normal. Decide how to handle them before training, and write the decision down.
  • Are the labels right? Labels are often late, incomplete or inconsistent. A fraud case may not be confirmed for weeks; some are never reported. A model learns the labels it is given, mistakes included.
  • Is it representative? If the examples come mostly from one region, one age group or one season, the model will be weakest for everyone else.
  • Does it reflect the past we want to repeat? Historical decisions can carry historical unfairness. A model trained on them can learn and repeat it.
  • May we use it? Data about people is personal data. Data protection laws, such as the EU's General Data Protection Regulation and Kenya's Data Protection Act, 2019, set rules on purpose, minimisation and security that apply to training data too.

One trap deserves its own name: data leakage. It happens when a feature contains information that would not be available at the moment the real decision is made. Suppose a fraud model is given the feature "account was later closed". It will look brilliant in testing, because closed accounts are often the fraud cases, and be useless in real life, because at the time of the payment nobody knows yet. If a result looks too good to be true, check for leakage first.

Lesson 4 of 5

Training, testing and overfitting

The goal of a model is not to do well on the examples it has seen. It is to do well on new examples it has never seen. This ability is called generalisation, and everything in this lesson is about measuring it honestly.

Split the data before you start:

  • The training set is what the model learns from.
  • The validation set is used to compare versions and tune settings while you work.
  • The test set is locked away and used once, at the end, to estimate real-world performance. If you keep checking the test set and adjusting, it stops being a fair test.

Overfitting is the central danger. An overfitted model has memorised its training examples, including their noise and accidents, instead of learning the underlying pattern. It is like a student who memorises last year's exam answers: perfect on those papers, lost on a new one. The sign is a large gap: excellent results on training data, much worse on validation data. The opposite, underfitting, is a model too simple to capture the pattern at all, and it does poorly on both.

Statisticians describe this as the bias–variance trade-off. A very simple model makes consistent but systematic errors (high bias). A very flexible model is thrown about by the particular examples it saw (high variance). The aim is the point in between that does best on new data.

Ways to keep a model honest:

  • Cross-validation: split the training data into several parts, train on all but one, test on the one left out, and rotate. The average gives a steadier estimate than a single split.
  • Respect time: when the data is a sequence over time, such as payments, always train on the past and test on a later period. Shuffling past and future together lets the model peek ahead.
  • Regularisation: methods that penalise needless complexity, nudging the model towards simpler patterns.
  • More, better data: often the most effective cure for overfitting.
  • Start with a baseline: a very simple model, or even a fixed rule. If your complex model cannot clearly beat it, you have learned something important cheaply.
Lesson 5 of 5

Measuring results and using ML responsibly

"Our model is 99.8% accurate" sounds impressive. Whether it is depends entirely on the question.

A worked example. A payment service checks 10,000 transactions. Twenty of them are fraud.

  • Model A marks every transaction as genuine. It is right 9,980 times out of 10,000: 99.8% accuracy. It also catches no fraud at all.
  • Model B flags 100 transactions for review. Fifteen of them are real fraud; 85 are genuine customers. It misses 5 frauds. Its accuracy is (15 + 9,895) ÷ 10,000 = 99.1%, lower than Model A, yet it is far more useful.

When the thing you care about is rare, accuracy hides it. The answer is to count the four outcomes separately, in what is called a confusion matrix. For Model B:

  • True positives: 15 frauds flagged and caught.
  • False positives: 85 genuine payments flagged by mistake (false alarms).
  • False negatives: 5 frauds not flagged (missed).
  • True negatives: 9,895 genuine payments correctly passed.

Two measures built from these tell you far more than accuracy:

  • Precision: of the cases flagged, how many were right? 15 ÷ 100 = 15%. Low precision means staff spend time on false alarms and customers are inconvenienced.
  • Recall: of the real cases, how many were caught? 15 ÷ 20 = 75%. Low recall means harm gets through.

Most models give a score, and you choose the threshold above which a case is flagged. Lowering it raises recall and lowers precision; raising it does the opposite. Where to set it is a business and risk decision, not a technical one: what does a missed fraud cost, and what does a false alarm cost? For regression models the usual measure is the size of the typical error, such as the mean absolute error: on average, how far off is the forecast?

Using ML responsibly. The US National Institute of Standards and Technology (NIST) describes three sources of bias in AI systems: systemic bias in institutions and the historical data they produce, statistical and computational bias from unrepresentative samples and modelling choices, and human bias in how people build, read and act on a model's output. Good practice follows from that:

  • Measure results for different groups, not only overall. A model can be accurate on average and poor for a minority.
  • Be able to explain what drives a decision, at least to the level the people affected and your regulator need.
  • Keep a person in the loop for decisions that matter, and record the model version behind every decision.
  • Monitor after launch. The world changes, and a model that was right last year can quietly drift.
In Kenya: the Data Protection Act, 2019 (section 35) gives people the right not to be subject to a decision based solely on automated processing, including profiling, that produces legal effects or significantly affects them, unless the decision is needed for a contract, authorised by law with safeguards, or based on their consent. Article 22 of the EU's General Data Protection Regulation contains a similar right.
Knowledge check

Ten questions

Answer all ten questions, then check your answers. You need 9 out of 10 to pass and receive a certificate. If you score less, you will see which answers were right and wrong, and then go through the course again before you retake the check. Your answers, progress and times are kept only in this browser.

Sources

The official documents this course relies on. Laws and guidance change, so check the current version.

  1. Some Studies in Machine Learning Using the Game of Checkers (1959) · Arthur L. Samuel, IBM Journal of Research and Development, vol. 3, no. 3
  2. Machine Learning (1997) · Tom M. Mitchell, McGraw-Hill
  3. An Introduction to Statistical Learning (free from the authors) · James, Witten, Hastie, Tibshirani and Taylor
  4. The Elements of Statistical Learning, 2nd edition (free from the authors) · Hastie, Tibshirani and Friedman
  5. Training Language Models to Follow Instructions with Human Feedback (2022) · Ouyang et al., arXiv
  6. Cross-validation: evaluating estimator performance · scikit-learn user guide (open-source project)
  7. NIST SP 1270: Towards a Standard for Identifying and Managing Bias in Artificial Intelligence (2022) · US National Institute of Standards and Technology
  8. AI Risk Management Framework (AI RMF 1.0) · US National Institute of Standards and Technology
  9. ISO/IEC 22989:2022, Artificial intelligence concepts and terminology · ISO and IEC
  10. General Data Protection Regulation (EU) 2016/679, Article 22 · EUR-Lex
  11. Data Protection Act, 2019 (No. 24 of 2019), section 35 · Kenya Law