Machine Learning Basics: What It Is and How It Works

In short: machine learning is the part of AI where a computer learns to do a task from examples, instead of being given step-by-step rules. You show it data - emails marked spam or not, house prices with their sizes, photos with labels - and it adjusts itself until its answers match. Then it can make predictions about new examples it has never seen.
What is machine learning, in simple words?
Machine learning is teaching a computer by example instead of by instruction. Imagine teaching a child to recognise a cat. You do not write a list of rules about whiskers and ear shapes; you point at many cats and say "cat". Machine learning works the same way: the program sees many labelled examples and works out the pattern itself.
That is the difference from ordinary programming:
| Ordinary programming | Machine learning |
|---|---|
| A person writes the rules | The program learns the rules from data |
| Input + rules → answer | Input + answers → rules (a "model") |
| Good for clear, fixed logic | Good for fuzzy patterns too complex to write down |
The term dates back to 1959, when Arthur Samuel published "Some Studies in Machine Learning Using the Game of Checkers", about a checkers program that got better by playing.
How does machine learning work, step by step?
Every machine-learning project follows the same basic loop: collect data, train a model, test it, then use it.
- Collect examples (data). For example, 10,000 past emails, each marked "spam" or "not spam".
- Describe each example with features. A feature is a measurable detail the model can use - such as which words an email contains, or a house's size and number of bedrooms. The answer you want it to learn is called the label - "spam", or the house's price. Google's machine learning glossary defines both terms.
- Train the model. The model starts by guessing. After each guess it measures how wrong it was - this measure is called the loss - and nudges its internal numbers to be a little less wrong next time. Repeated over all the examples many times, the guesses improve.
- Test it on examples it has not seen. Part of the data is kept aside and never used in training. Scoring the model on this test set shows whether it learned the real pattern or just memorised the training examples.
- Use it. The trained model now makes predictions on new data - flagging tomorrow's spam, estimating a new house's price.
What are the three main types of machine learning?
The three main types are supervised learning, unsupervised learning and reinforcement learning, depending on what kind of feedback the model gets.
1. Supervised learning: learning with answers
The model learns from examples that already have the right answer attached. It is the most common type. It comes in two flavours:
- Classification - predicting a category. Is this email spam? Is this X-ray normal? Which digit is in this picture?
- Regression - predicting a number. What will this house sell for? How many umbrellas will we sell next week?
The hard part is usually the labels: someone has to mark thousands of examples correctly first.
2. Unsupervised learning: finding structure without answers
The model gets data with no labels and finds groups or patterns on its own. For example:
- Clustering - a shop gives the model its customers' purchase histories, and the model groups similar customers into segments nobody defined in advance.
- Dimensionality reduction - squeezing data with hundreds of features down to a few that capture most of the differences, often to plot it or speed up other models.
Because there is no right answer to check against, judging whether the result is useful takes human judgement.
3. Reinforcement learning: learning by trial and error
The model takes actions, gets rewards or penalties, and learns which actions earn the most reward over time. A program learning a video game gets points for progress and learns a strategy from that score alone, without ever being told the right move. Richard Sutton and Andrew Barto's textbook Reinforcement Learning: An Introduction (2nd edition, MIT Press, 2018) is a widely used textbook on the subject.
Reinforcement learning is also part of how chatbots are trained: in reinforcement learning from human feedback (RLHF), people rate pairs of answers and the model is rewarded for the kind they prefer (Ouyang et al., 2022).
A fourth idea: self-supervised learning
Large language models mostly learn with self-supervision: the data provides its own answers. A model reads a sentence with the next word hidden and tries to predict it; the real next word is the answer. No one has to label anything, which is why these models can learn from enormous amounts of text. See how LLMs work for the full training pipeline.
Common machine-learning methods, explained simply
- Linear regression - draws the best straight line through data points, for example house size against price, and uses it to predict.
- Logistic regression - despite the name, a method for yes/no classification, such as spam or not spam.
- Decision tree - a flowchart of yes/no questions ("Does the email mention a prize? Is the sender unknown?") that ends in an answer.
- Random forest - many decision trees, each trained a little differently, that vote on the answer.
- k-means clustering - an unsupervised method that groups data into k clusters of similar points.
- Neural network - layers of simple mathematical units that pass numbers forward; with many layers it becomes deep learning, the approach behind image recognition and chatbots.
The scikit-learn user guide, the documentation of a widely used free Python library, organises these and many more methods under supervised and unsupervised learning.
What is overfitting?
Overfitting is when a model memorises its training examples instead of learning the general pattern, so it does well in training and badly on new data. It is like a student who memorises last year's exam answers and fails when the questions change. The opposite, underfitting, is a model too simple to capture the pattern at all.
The usual defences: keep a separate test set to catch it, use more and more varied data, and keep the model no more complex than the problem needs.
Where is machine learning used?
- Email - spam filters.
- Banking - flagging unusual card payments as possible fraud.
- Shopping and streaming - recommendations based on what similar people chose.
- Health - helping read medical images such as X-rays and scans.
- Maps - predicting traffic and arrival times.
- Phones - face unlock, speech recognition and photo search.
- Chatbots - ChatGPT, Claude and Gemini are machine-learning models trained on text.
How AI, machine learning and deep learning fit together
AI is the whole field, machine learning is one way of doing AI, and deep learning is one kind of machine learning. Large language models are a kind of deep learning trained on text. So every chatbot model is machine learning, but not all machine learning is a chatbot - a simple spam filter is machine learning too. Our guide to what AI is covers the bigger picture.
How to start learning machine learning
Free courses that start from zero are listed on our AI for beginners courses page. Two that teach machine learning directly: Google's Machine Learning Crash Course, with interactive visualisations and exercises, and Kaggle's Intro to Machine Learning, which uses Python.
Words to know
- Model - what training produces: the learned pattern used to make predictions.
- Training - the process of adjusting a model using examples.
- Feature - a measurable detail of an example, such as a house's size.
- Label - the answer the model should learn, such as the house's price.
- Loss - a number measuring how wrong the model's guesses are.
- Test set - examples kept aside to check the model on data it has not seen.
- Overfitting - memorising the training data instead of learning the pattern.
- Neural network / deep learning - layered models that learn complex patterns.
Related guides
Frequently asked questions
What is machine learning in simple terms?+
Machine learning is a way of building software that learns to do a task from examples instead of following rules a programmer wrote. After seeing many examples, such as emails marked spam or not spam, it can make predictions about new ones.
What are the three types of machine learning?+
Supervised learning, which learns from examples with the right answers attached; unsupervised learning, which finds groups and patterns in unlabelled data; and reinforcement learning, which learns by trial and error from rewards and penalties.
What is the difference between AI and machine learning?+
Artificial intelligence is the whole field of making computers do tasks that need intelligence. Machine learning is one approach to AI, in which the system learns from data. Most AI in use today is built with machine learning.
What is an example of machine learning?+
An email spam filter is a common example. It is trained on many emails already marked as spam or not spam, learns which patterns go with each, and then sorts new emails automatically.
Do I need maths to learn machine learning?+
Not to understand the ideas or to start using tools. Building and tuning models yourself uses some statistics, algebra and programming, usually Python; free courses such as Google's Machine Learning Crash Course and Kaggle's Intro to Machine Learning introduce these step by step.
What is overfitting in machine learning?+
Overfitting is when a model memorises its training data instead of learning the general pattern, so it performs well on examples it has seen and poorly on new ones. Testing on held-back data is the usual way to detect it.
Is ChatGPT machine learning?+
Yes. ChatGPT runs on large language models, which are deep-learning models, a kind of machine learning, trained on very large amounts of text to predict the next word.
Enjoyed this? Get more in your inbox.
Up to ten of the week's AI news stories, by email once a week.