Q&A
What are the types of machine learning?
Overview
The choice of learning type is determined by what data you have and what you want to learn. If you have labelled examples, supervised learning maps inputs to outputs. If you have lots of data but no labels, unsupervised methods discover structure. If you have an environment to interact with and a reward signal, reinforcement learning optimizes behaviour over time.
graph TD
A[Machine Learning] --> B[Supervised: labelled data → predict y]
A --> C[Unsupervised: unlabelled data → find structure]
A --> D[Reinforcement: agent + environment → maximize reward]
A --> E[Self-supervised: predict part from part → pretrain representations]
style A fill:#1e1b4b,color:#fff
Supervised Learning
What: Learn a function f(x) → y from labelled training examples (x, y).
Two main tasks:
- Classification - predict a discrete class label: spam/not-spam, dog/cat/bird.
- Regression - predict a continuous value: house price, temperature, stock return.
Examples: linear/logistic regression, decision trees, random forests, SVMs, neural networks for image recognition and NLP.
Requires: labelled data - often the bottleneck (labelling is expensive and time-consuming).
# Supervised: train on (X_train, y_train), predict on X_test
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier()
clf.fit(X_train, y_train)
preds = clf.predict(X_test)
Unsupervised Learning
What: Discover hidden structure in data with no labels.
Key tasks:
- Clustering - group similar points together (k-means, DBSCAN, hierarchical clustering).
- Dimensionality reduction - compress high-dimensional data to a lower-dimensional representation (PCA, t-SNE, UMAP).
- Density estimation - model the underlying distribution of data.
- Anomaly detection - identify unusual points that don't fit the learned structure.
- Generative modelling - learn to produce new samples (VAEs, GANs, diffusion models).
Use when: you have lots of data but no labels - exploratory analysis, customer segmentation, compression, data visualization.
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=5)
labels = kmeans.fit_predict(X) # no y needed
Reinforcement Learning
What: An agent learns a policy (which action to take in each state) to maximize cumulative reward from an environment over time.
Key concepts: State (S), Action (A), Reward (R), Policy π, Value function V, Q-function Q(s,a).
Use when: you can simulate or interact with an environment and define a reward - game playing (AlphaGo, Dota2), robot control, recommendation systems, RLHF for LLM alignment.
Challenge: sample-inefficient (needs millions of environment interactions), reward design is hard, credit assignment problem.
Self-Supervised Learning
What: Use the structure of data to construct supervision automatically, without human labels. Predict a masked word from context (BERT), predict the next token (GPT), or predict one view of an image from another (SimCLR).
Why it matters: Enables pretraining on internet-scale unlabelled data. This is what powers LLMs and strong vision models - self-supervised pretraining, then fine-tune on a small labelled dataset.
Comparison Table
| Supervised | Unsupervised | Reinforcement | Self-supervised | |
|---|---|---|---|---|
| Data | Labelled (x, y) | Unlabelled x | Environment + reward | Unlabelled, auto-labeled |
| Goal | Predict y | Find structure | Maximize reward | Learn representations |
| Key challenge | Labelling cost | Evaluating results | Sample efficiency | Pretext task design |
| Examples | Classifiers, regression | Clustering, PCA | Game AI, robotics | BERT, GPT, SimCLR |
Why This Matters in Interviews
This is one of the most fundamental ML interview questions. Be precise: supervised = labelled data, predict outputs; unsupervised = no labels, find structure; RL = agent-environment loop with reward. Mentioning self-supervised as the fourth type powering LLMs is a strong current-awareness signal. Knowing specific algorithms for each type (random forest, k-means, Q-learning, BERT) and the label-cost trade-off grounds the theory in practice.
Common Pitfalls
- Describing supervised/unsupervised as dichotomies - there's a spectrum (semi-supervised, self-supervised).
- Forgetting that RL is fundamentally different in requiring environment interaction and sequential decisions.
- Claiming unsupervised learning is "easier" - no labels makes it hard to evaluate.
- Not knowing that modern LLMs use self-supervised pretraining (the most important ML paradigm today).
References
- Goodfellow et al., Deep Learning: https://www.deeplearningbook.org/
- OpenAI Spinning Up (RL): https://spinningup.openai.com/