
Machine learning (ML) is a way of building software that learns from examples instead of following rules written by a programmer. You show a machine learning model thousands of emails labelled “spam” or “not spam”, photos labelled with what is in them, or past house sales with their prices, and the model works out the patterns by itself. Then it applies those patterns to new data it has never seen.
Machine learning is behind almost every “smart” feature you use: search results, recommendations on YouTube and Netflix, spam filters, fraud detection on your bank card, face unlock on your phone, translation, and the large language models behind ChatGPT, Claude and Gemini. This guide explains what machine learning is in simple words, how it works, its main types and algorithms, and how it relates to AI and deep learning. You will also train your first models in a few lines of Python and see, with our own experiment, why data matters more than anything else.
Key takeaways
- Machine learning is a branch of artificial intelligence in which computers learn patterns from data instead of being explicitly programmed.
- Three main types: supervised learning (learning from labelled examples), unsupervised learning (finding structure in unlabelled data) and reinforcement learning (learning by trial and error from rewards). Large language models add a fourth, self-supervised learning.
- Deep learning is a subset of machine learning that uses neural networks with many layers; generative AI is built on deep learning.
- A model is only as good as its data. In our experiment, the same algorithm went from 69% to 96% accuracy simply by training on more examples.
- The real test is new data: a model that memorises its training set (100% accuracy) can still fail on examples it has not seen. This is called overfitting.
What is machine learning?
In traditional programming, a developer writes rules: if an email contains “you have won” and comes from an unknown sender, mark it as spam. This works until spammers change their wording, and for many tasks nobody can write the rules at all. Try describing in code exactly what makes a photo show a cat rather than a dog.
Machine learning turns this around. Instead of rules, you give the computer examples together with the correct answers, and a learning algorithm finds the rules itself. The result is a model: a program whose behaviour was learned from data rather than written by hand.
The idea is old. Arthur Samuel, who built a checkers program that improved by playing against itself, coined the term in 1959 and is usually credited with defining machine learning as the field that gives computers the ability to learn without being explicitly programmed. A more precise definition comes from Tom Mitchell’s 1997 textbook: a program learns from experience E with respect to a task T and a performance measure P if its performance on T, measured by P, improves with E. For a spam filter, T is sorting emails, P is the share of emails sorted correctly, and E is a collection of emails labelled by users.
What changed in the last fifteen years is scale. Machine learning needs a lot of data and computing power, and both became cheap: the internet produced billions of examples, and graphics cards (GPUs) made training large models fast. That is why ML moved from research labs into almost every product.
How does machine learning work?
Every machine learning project, from a spam filter to a large language model, follows the same steps:
- Collect data. Examples of the problem, such as emails, images, sensor readings or transactions, usually with the correct answer (the label) for each one.
- Choose features. Decide which measurable properties describe each example: the size and location of a house, the pixels of an image, the words of a sentence. Deep learning models learn useful features from raw data themselves.
- Choose a model. A family of functions with adjustable parameters: a straight line, a decision tree, a neural network.
- Train. The learning algorithm adjusts the parameters to make the model’s predictions match the labels. It measures the error with a loss function and reduces it step by step, usually with gradient descent.
- Evaluate on new data. Test the model on examples it did not see during training. Only this tells you whether it learned real patterns or just memorised the training set.
- Deploy and monitor. Use the model in an application and keep checking it, because the world changes and a model trained on last year’s data slowly becomes outdated.
Here is what training looks like for a small neural network that classifies iris flowers. Four measurements of a flower enter on the left; numbers on the connections are the parameters (weights) that the algorithm adjusts during training; the three outputs on the right are the probabilities of the three species:

Learning is the gradual adjustment of these numbers. Each time the network makes a wrong prediction, the algorithm nudges every weight slightly in the direction that would have made the error smaller, a procedure called backpropagation. After thousands of such nudges, the network classifies flowers it has never seen.
Types of machine learning
Machine learning methods are usually grouped by the kind of feedback the model gets during training.
Supervised learning
The model learns from labelled examples: inputs paired with correct outputs. This is the most common type in business applications. It solves two kinds of problems:
- Classification predicts a category: spam or not, which digit is in an image, whether a transaction is fraudulent, which disease an X-ray shows.
- Regression predicts a number: a house price, tomorrow’s electricity demand, the delivery time of an order. The classic method is linear regression.
Unsupervised learning
The model gets data without labels and looks for structure in it. Clustering groups similar items, for example customers with similar buying habits. Dimensionality reduction compresses many features into a few, for visualisation or as a preprocessing step. Anomaly detection flags unusual data points, such as a failing machine on a factory line. We compare the first two types in detail in supervised vs unsupervised learning.
Reinforcement learning
An agent learns by acting in an environment and receiving rewards or penalties, with no correct answers given in advance. This is how computers learned to beat world champions at Go and how robots learn to walk in simulation. Reinforcement learning from human feedback (RLHF) and from verifiable rewards is also a key step in training today’s chatbots and reasoning models.
Self-supervised learning
A fourth approach powers modern AI: the data provides its own labels. A language model is trained to predict the next word of a text, so every sentence on the internet becomes a training example without any human labelling. Large language models, image generators and speech recognition systems are pretrained this way on huge data sets and then fine-tuned for specific tasks.
Machine learning vs AI vs deep learning
These terms are often used interchangeably, but they are nested inside each other:
| Term | What it means | Example |
|---|---|---|
| Artificial intelligence (AI) | Any technique that makes computers perform tasks that seem to require intelligence, including hand-written rules | A chess engine with hand-tuned rules, a route planner |
| Machine learning (ML) | The part of AI in which behaviour is learned from data | A spam filter, a credit scoring model, a recommender system |
| Deep learning | The part of ML that uses neural networks with many layers, which learn features from raw data | Face recognition, speech recognition, machine translation |
| Generative AI | Deep learning models that create new text, images, audio or code | ChatGPT, Claude, Gemini, image and video generators |
So all machine learning is AI, but not all AI is machine learning; all deep learning is machine learning, but classic algorithms such as decision trees and logistic regression are machine learning without being deep learning. They are still the best choice for many problems with tables of numbers, where they are faster, cheaper and easier to explain than neural networks.
Deep learning shines on images, sound and text. Its networks learn a hierarchy of features automatically: the first layers of an image model detect edges, the next ones shapes, the last ones whole objects. You can see it in this visualisation of a convolutional neural network recognising a handwritten digit:

Common machine learning algorithms
Dozens of algorithms exist, but a handful cover most practical work:
| Algorithm | Type | How it works | Typical use |
|---|---|---|---|
| Linear regression | Supervised, regression | Fits a straight line (or plane) through the data | Prices, forecasts, trends |
| Logistic regression | Supervised, classification | A linear model that outputs a probability | Credit scoring, medical risk, click prediction |
| Decision tree | Supervised | A sequence of yes/no questions about the features | Explainable decisions, quick baselines |
| Random forest, gradient boosting | Supervised | Combine hundreds of decision trees | Tabular data: fraud, churn, ranking; strong default choice |
| k-nearest neighbours | Supervised | Predicts from the most similar known examples | Simple recommendations, small data sets |
| Naive Bayes | Supervised, classification | Applies Bayes’ theorem to word or feature counts | Spam filtering, text classification |
| k-means | Unsupervised, clustering | Groups points around k centres | Customer segmentation |
| Neural networks | Any | Layers of simple units, from the perceptron to transformers | Images, text, speech, generative AI |
For data in tables, gradient-boosted trees are usually the strongest starting point. For images, sound and text, neural networks dominate: convolutional networks for images, recurrent networks and now mostly transformers for sequences.
Your first machine learning model in Python
The most popular library for classic machine learning is scikit-learn. It gives every algorithm the same interface: create a model, call fit with training data, then predict or score on new data. The example below uses the iris data set, collected by the botanist Edgar Anderson and made famous by the statistician Ronald Fisher in 1936: 150 flowers of three species with four measurements each. It trains five different algorithms and tests them on flowers they have not seen. Install the library with pip install scikit-learn; the data set is included.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.neural_network import MLPClassifier
# 1. Data: 150 iris flowers, 4 measurements each (cm), 3 species
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42, stratify=y)
print(f"training examples: {len(X_train)}, test examples: {len(X_test)}")
# 2. Five different learning algorithms, same two lines each: fit, then score on unseen data
models = {
"Logistic regression": LogisticRegression(max_iter=1000),
"k-nearest neighbours": KNeighborsClassifier(n_neighbors=5),
"Decision tree": DecisionTreeClassifier(random_state=42),
"Random forest": RandomForestClassifier(random_state=42),
"Neural network": MLPClassifier(hidden_layer_sizes=(16,), max_iter=2000, random_state=42),
}
for name, model in models.items():
model.fit(X_train, y_train) # learn from examples
print(f"{name:22s} test accuracy {model.score(X_test, y_test):.3f}")
# 3. Use a trained model on a new flower: sepal length, sepal width, petal length, petal width
species = load_iris().target_names
new_flower = [[6.1, 2.8, 4.7, 1.2]]
tree = models["Decision tree"]
print("prediction:", species[tree.predict(new_flower)[0]])
probs = models["Logistic regression"].predict_proba(new_flower)[0]
print("probabilities:", {str(name): round(float(p), 3) for name, p in zip(species, probs)})
training examples: 105, test examples: 45
Logistic regression test accuracy 0.933
k-nearest neighbours test accuracy 0.978
Decision tree test accuracy 0.933
Random forest test accuracy 0.889
Neural network test accuracy 1.000
prediction: versicolor
probabilities: {'setosa': 0.005, 'versicolor': 0.846, 'virginica': 0.15}
All five models learned to tell the species apart from just 105 examples, with 89% to 100% accuracy on the 45 test flowers. The differences between them are small and partly luck: with only 45 test flowers, a single mistake changes the score by more than two percentage points. For a new flower the model returns the most likely species and, for most algorithms, the probability of each class: here logistic regression is 85% sure the flower is versicolor.
Notice the split into training and test sets. A model is always judged on data it did not learn from, just as a student is tested on new problems rather than the ones solved in class.
Why data matters: more examples, better models
How much does the amount of training data matter? We ran an experiment on scikit-learn’s digits data set: 1,797 handwritten digits of 8×8 pixels. We set aside 360 digits for testing and trained three algorithms on random subsets of 25 to 1,437 of the remaining images, averaging five runs for each size:
import json
import numpy as np
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
# 1,797 handwritten digits, 8x8 pixels; 360 are kept aside as a fixed test set
X, y = load_digits(return_X_y=True)
X_pool, X_test, y_pool, y_test = train_test_split(X, y, test_size=360, random_state=0, stratify=y)
models = {
"Logistic regression": lambda: LogisticRegression(max_iter=5000),
"Decision tree": lambda: DecisionTreeClassifier(random_state=0),
"Random forest": lambda: RandomForestClassifier(random_state=0),
}
sizes = [25, 50, 100, 200, 400, 800, 1437]
rng = np.random.default_rng(0)
results = {name: [] for name in models}
for n in sizes:
for name, make in models.items():
scores = []
for _ in range(5): # 5 random training subsets of size n
idx = rng.choice(len(X_pool), n, replace=False)
model = make().fit(X_pool[idx], y_pool[idx])
scores.append(model.score(X_test, y_test))
results[name].append(float(np.mean(scores)))
print(f"{n:5d} examples " + " ".join(f"{name.split()[0]} {results[name][-1]:.3f}" for name in models))
# Overfitting: a decision tree memorises its training data
tree = DecisionTreeClassifier(random_state=0).fit(X_pool, y_pool)
print(f"decision tree: training accuracy {tree.score(X_pool, y_pool):.3f}, test accuracy {tree.score(X_test, y_test):.3f}")
json.dump({"sizes": sizes, **results}, open("more_data.json", "w"))
25 examples Logistic 0.692 Decision 0.356 Random 0.581
50 examples Logistic 0.815 Decision 0.469 Random 0.703
100 examples Logistic 0.897 Decision 0.627 Random 0.841
200 examples Logistic 0.926 Decision 0.698 Random 0.908
400 examples Logistic 0.941 Decision 0.754 Random 0.944
800 examples Logistic 0.958 Decision 0.822 Random 0.948
1437 examples Logistic 0.958 Decision 0.878 Random 0.966
decision tree: training accuracy 1.000, test accuracy 0.878

Three lessons follow from these numbers:
- More data beats a cleverer algorithm. Logistic regression trained on 25 digits recognises 69% of test digits; with 400 digits, 94%. Every algorithm improves steadily as it sees more examples, and the gains slow down only near the end.
- Algorithms differ most when data is scarce. With 25 examples, the random forest is far behind logistic regression (58% vs 69%); from 400 examples on, the two are within about one point of each other, and on the full training set the forest is slightly ahead (96.6% vs 95.8%).
- Training accuracy is not test accuracy. A single decision tree reaches 100% accuracy on its own training images but only 87.8% on new ones. It has memorised the training set, noise included, instead of learning general rules. This is overfitting, the most common failure in machine learning. Random forests reduce it by averaging many different trees, and neural networks fight it with more data, regularisation and early stopping.
This is the same reason modern AI models are trained on such enormous data sets. Large language models see trillions of words, and their quality has grown mostly with more data, larger models and more computing power.
Machine learning examples in everyday life

- Recommendations: what to watch on Netflix and YouTube, what to buy on Amazon, which posts appear in your feed.
- Search and language: ranking search results, autocomplete, machine translation, and chatbots built on large language models.
- Finance: detecting fraudulent card transactions in milliseconds, credit scoring, algorithmic trading.
- Health: spotting tumours in medical scans, predicting patient risk, accelerating drug discovery.
- Images and video: face unlock, photo search (“show me pictures of dogs”), camera night modes and AI photo enhancement.
- Transport and industry: driver assistance and self-driving cars, delivery route planning, predicting machine failures before they happen.
- Email and security: spam filtering, malware detection, detecting suspicious logins.
Adoption is now close to universal among companies. According to the Stanford AI Index 2026, 88% of organisations use AI, and generative AI reached 53% of the population within three years. McKinsey’s State of AI survey from mid-2026 paints a more sober picture: nearly nine in ten companies use AI regularly in at least one function, but only 37% of respondents report any measurable effect on profit.
Limitations and risks
Machine learning is powerful but not magic. The main problems are well known:
- Data quality. Errors, gaps and outdated records in the training data become errors in the model. “Garbage in, garbage out” is the first rule of ML.
- Bias. A model trained on historical decisions learns the biases in those decisions, for example in hiring or lending, unless the data and results are carefully checked.
- Overfitting and distribution shift. A model can work on test data and still fail in production when real-world data differs from the training data, for example after a change in customer behaviour.
- Explainability. Large models, especially deep neural networks, are hard to interpret. In medicine, finance and law, it matters why a model made a decision, not just what it decided.
- Cost and energy. Training frontier models requires huge computing clusters. Most practical problems, however, are solved with small models that train in seconds on a laptop, like the ones in this guide.
How to learn machine learning in 2026
You do not need a PhD to start. A practical path:
- Python. The language of machine learning. Learn the basics, then NumPy for arrays and pandas for tables of data.
- Classic ML with scikit-learn. Train models on small data sets, as above. Learn to split data, choose metrics and spot overfitting. Kaggle competitions, such as the one in our Titanic tutorial, and its free courses are good practice.
- The maths, as you need it. Linear algebra (vectors and matrices), probability and statistics, and a little calculus for derivatives. You can learn them alongside the code rather than before it.
- Deep learning. Move to a framework: PyTorch is the standard in 2026; our PyTorch vs TensorFlow comparison explains why, and our PyTorch tutorial gets you started. Then learn the core architectures, from CNNs to GANs.
- Courses. Popular starting points include Andrew Ng’s Machine Learning Specialization on Coursera, Google’s free Machine Learning Crash Course and fast.ai’s Practical Deep Learning for Coders.
When you are ready to apply for jobs, our list of data science interview questions shows what employers test, from statistics to ML system design.
A laptop is enough for everything up to small neural networks. When you need more power, free GPU notebooks such as Google Colab and Kaggle, or rented cloud GPUs, cover most needs; see our guide to the best GPU for AI if you want your own.
FAQ
What is machine learning in simple words?
Machine learning is teaching computers by example. Instead of writing step-by-step instructions, you give the computer many examples with the right answers, and it figures out the pattern so it can answer new questions of the same kind.
What is the difference between AI and machine learning?
AI is the broad goal of making computers do intelligent things, by any method, including hand-written rules. Machine learning is the most successful way of doing it today: the computer learns its behaviour from data. Almost every AI system you hear about in 2026, including chatbots and image generators, is built with machine learning.
What are the 3 types of machine learning?
Supervised learning learns from labelled examples, unsupervised learning finds patterns in unlabelled data, and reinforcement learning learns from rewards by trial and error. Self-supervised learning, used to pretrain large language models, is often added as a fourth type.
What is a machine learning model?
A model is the result of training: a function with learned parameters that turns an input, such as an email, image or row of data, into an output, such as a category, a number or a piece of text. A trained model can be saved and used in applications without the training data.
Is machine learning hard to learn?
The basics are accessible to anyone who can program a little: as the examples above show, training a working model takes a few lines of Python. Becoming good at it takes longer, because you need statistics, experience with real, messy data and the judgement to evaluate models honestly.
Does machine learning need a lot of data?
It depends on the task. Simple problems can be solved with hundreds of examples, as in our experiments; image or speech recognition from scratch needs many thousands or millions. Pretrained models reduce the need: fine-tuning an existing model often works with a few hundred labelled examples.









