What Is Machine Learning?
The big picture of AI and machine learning — learning from data instead of rules, supervised, unsupervised, self-supervised and reinforcement learning, the ML workflow, features and labels, generalisation, and where deep learning and LLMs fit.
Machine learning (ML) is the practice of building programs that learn patterns from data instead of following hand-written rules.
Rules + data → answers.
A programmer writes if subject contains "lottery" and sender unknown → spam. Every case must be anticipated; rules break as spammers adapt.
Data + answers → rules.
Show the algorithm thousands of emails labelled spam / not spam; it learns a function that classifies new emails, and can be retrained as patterns change.
ML shines when rules are too complex to write (recognising faces, translating language), when patterns change over time (fraud), or when you need to find structure humans can't see (recommendations).
AI, ML, deep learning, generative AI
Types of learning
| Type | Data | Goal | Examples |
|---|---|---|---|
| Supervised | Inputs with labels | Predict the label for new inputs | Spam detection, house prices, image classification, diagnosis |
| Unsupervised | Inputs without labels | Find structure | Customer segmentation (clustering), anomaly detection, dimensionality reduction |
| Self-supervised | Unlabelled data where the labels come from the data itself | Learn general representations | LLMs predicting the next word; masked image modelling |
| Reinforcement learning | An agent acting in an environment, receiving rewards | Learn a policy maximising reward | Game playing (AlphaGo), robotics, RLHF for chatbots |
Supervised learning splits into:
- Regression: predict a number (price, temperature, delivery time).
- Classification: predict a category (spam/not spam, digit 0–9, cat/dog/bird).
Vocabulary
| Term | Meaning |
|---|---|
| Example / sample | One data point (an email, a house) |
| Features | The inputs describing an example (square metres, bedrooms, location) — the vector x |
| Label / target | The answer to predict (the price) — y |
| Model | A function with adjustable parameters (weights) mapping features to predictions |
| Training | Adjusting parameters to minimise a loss (error) on training data |
| Inference | Using the trained model to predict on new data |
| Hyperparameters | Settings chosen before training (learning rate, tree depth, number of layers) |
The ML workflow
- Frame the problem: what decision does the prediction support? What metric defines success? Is ML even needed — would a simple rule work?
- Collect and label data: often the hardest and most important step.
- Explore and clean: missing values, outliers, errors, leakage, class imbalance.
- Feature engineering: transform raw data into useful inputs (deep learning automates much of this).
- Split the data: training, validation and test sets.
- Train candidate models, starting with a simple baseline.
- Evaluate on validation data, tune hyperparameters, then report final performance on the untouched test set (Model evaluation).
- Deploy and monitor: watch for data drift and degrading accuracy; retrain (MLOps).
Generalisation: the central challenge
The goal isn't to do well on training data — a lookup table can memorise that — but to generalise to data the model has never seen.
| Problem | Symptom | Cause | Fixes |
|---|---|---|---|
| Underfitting (high bias) | Poor on training and test data | Model too simple | More features, a more expressive model, train longer |
| Overfitting (high variance) | Great on training, poor on test | Model memorises noise | More data, regularisation, simpler model, early stopping, dropout |
The bias–variance trade-off describes this tension. This is why we always evaluate on held-out data.
A first model in a few lines
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import classification_report
X, y = load_breast_cancer(return_X_y=True) # 569 tumours, 30 features, benign/malignant
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
model.fit(X_train, y_train) # training
print(classification_report(y_test, model.predict(X_test))) # evaluation on unseen dataWhere deep learning and LLMs fit
Classical ML (linear models, decision trees, gradient boosting — Classical ML algorithms) excels on tabular data with meaningful features. Deep learning (Neural networks) dominates unstructured data — images, audio, text — learning features automatically from raw inputs given lots of data and compute. Large language models (LLMs) are huge transformers trained with self-supervision on internet-scale text, then adapted to follow instructions.
Limits and responsibilities
- Models learn correlations, not causation, and only what's in the data.
- Bias in data becomes bias in predictions (hiring, lending, policing) — measure fairness across groups.
- Models can be confidently wrong, especially on inputs unlike the training data (distribution shift).
- Privacy, explainability, security (adversarial examples, prompt injection) and regulation (e.g. the EU AI Act) matter in production.
- ML learns rules from data and answers instead of having them hand-coded.
- AI ⊃ ML ⊃ deep learning ⊃ generative models and LLMs.
- Supervised (regression, classification), unsupervised, self-supervised and reinforcement learning.
- Workflow: frame, collect, clean, featurise, split, train baseline, evaluate, deploy, monitor.
- The goal is generalisation; underfitting and overfitting are the two failure modes.
- Classical ML wins on tabular data; deep learning on images, audio and text.