Skip to content
Kuza Ndoto Academy

Introduction to Machine Learning

IntermediateChapter 1 · Page 1 of 264 min readUpdated 15 Nov 2026

Machine learning (ML) is a branch of artificial intelligence in which computers learn patterns from data instead of following rules written by hand. Give a learning algorithm enough good examples and it produces a model that can make predictions about cases it has never seen.

Traditional programming vs. machine learning

In ordinary programming you write the rules yourself. That works well when the rules are clear, such as calculating VAT. It breaks down when the rules are fuzzy or change often, such as deciding whether an SMS is a scam. Machine learning flips the process: you supply examples with the correct answers, and the algorithm works out the rules.

Traditional programmingMachine learning
You provideData + rules written by a programmerData + the correct answers (examples)
You getAnswersRules (a trained model) that produce answers
Example"If the message contains 'you have won', mark it as spam"Learn what spam looks like from 10,000 labelled messages
Traditional programming Data Rules Program Answers Machine learning Data Answers (labels) Learning algorithm Rules (a model)
Figure 1. Machine learning swaps inputs and outputs: you supply examples with answers, and the algorithm produces the rules.

Key vocabulary

  • Dataset: a table of examples. Each row is one example (a house, a customer, a photo).
  • Features: the inputs the model learns from, such as size, location and number of bedrooms.
  • Label (target): the answer you want to predict, such as the rent.
  • Training: the process of adjusting the model so its predictions match the labels.
  • Model: the result of training, which you can save and use to predict.

These ideas are covered in detail on the Features & Labels page.

How machine learning works

  1. Collect data: for example, past house rentals with their size, location and monthly rent.
  2. Prepare the data: clean it and choose useful features.
  3. Train a model: an algorithm finds the pattern that links features to the label.
  4. Evaluate: test the model on data it has never seen.
  5. Predict: use the model on new, real-world cases, and keep monitoring it.

The full process is explained in The Machine Learning Workflow.

A tiny example in Python

Here a model learns the link between hours studied and exam score, then predicts the score for a student who studies for 6 hours. It uses scikit-learn, the most popular Python library for classic machine learning (install it with pip install scikit-learn; see pip & Virtual Environments).

from sklearn.linear_model import LinearRegression

hours = [[1], [2], [3], [4], [5]]      # feature: hours studied (one column)
scores = [52, 58, 65, 71, 78]          # label: exam score

model = LinearRegression()
model.fit(hours, scores)               # learn the pattern

prediction = model.predict([[6]])
print(f"Predicted score for 6 hours: {prediction[0]:.0f}")
Predicted score for 6 hours: 84

The model found the best straight line through the five points: each extra hour adds about 6.5 marks, starting from about 45.3. For 6 hours that gives 45.3 + 6.5 × 6 = 84.3, which prints as 84. Notice that the features are a list of lists: scikit-learn always expects a 2-D table of features, even when there is only one column.

Types of machine learning

  • Supervised learning: learns from labelled examples, e.g. predicting whether a loan will be repaid.
  • Unsupervised learning: finds structure in unlabelled data, e.g. grouping customers into segments.
  • Reinforcement learning: learns by trial, error and reward, e.g. game-playing agents.

Each type has its own section; start with Types of Machine Learning.

Where you already use machine learning

  • Spam filters in your email and SMS inbox
  • Recommendations on YouTube, TikTok and Spotify
  • Fraud alerts from mobile money services and banks
  • Voice assistants, translation apps and chatbots
  • Apps that spot crop diseases from a phone photo of a leaf
Warning

A model is only as good as its data. Old, biased or incomplete data leads to wrong or unfair predictions, and a model can be confidently wrong. That is why this series ends with Bias & Fairness and AI Ethics & Safety.

Key points

  • Machine learning finds patterns in data instead of following hand-written rules.
  • Features are the inputs; the label is the answer you want to predict.
  • The workflow is: collect, prepare, train, evaluate, predict.
  • The three main types are supervised, unsupervised and reinforcement learning.
Up next · IntroductionTypes of Machine LearningSupervised, unsupervised and reinforcement learning.
→

Tip: use the ← and → keys to move between pages.