indusai.co

Types of machine learning

Machine learning problems are grouped by what kind of feedback the algorithm gets while learning. The three main families are supervised, unsupervised and reinforcement learning. Almost everything on this site falls into the first two.

Supervised learning

Every training example comes with the correct answer (the label). The algorithm learns to map inputs to those answers, and is scored on how close its predictions are.

There are two kinds of supervised problem, decided by the type of label:

  • Regression: the label is a number. Predict rent, temperature, sales, delivery time.
  • Classification: the label is a category. Spam or not, which digit is in the image, will the customer churn.
python
from sklearn.linear_model import LogisticRegression

# hours studied, hours slept  ->  passed the exam?
X = [[2, 8], [4, 7], [1, 5], [6, 8], [3, 4], [7, 6], [5, 5], [0, 9]]
y = [0, 1, 0, 1, 0, 1, 1, 0]

clf = LogisticRegression().fit(X, y)
print(clf.predict([[5, 7], [1, 8]]))

Supervised learning is by far the most common in industry because business data usually comes with outcomes attached: past sales, past defaults, past clicks.

Unsupervised learning

There are no labels. The algorithm looks for structure in the inputs alone.

  • Clustering: group similar examples. Customer segments, grouping news articles by topic.
  • Dimensionality reduction: compress many features into a few while keeping most of the information. Visualising high dimensional data, speeding up other models.
  • Anomaly detection: find examples that do not look like the rest. Fraud, faulty sensors.
python
from sklearn.cluster import KMeans

# annual spend, visits per month
customers = [[200, 1], [250, 2], [180, 1], [3000, 12], [2800, 10], [3200, 15]]
km = KMeans(n_clusters=2, n_init=10, random_state=0).fit(customers)
print(km.labels_)

The algorithm was never told there are "casual" and "loyal" customers, but it separated them.

Reinforcement learning

An agent takes actions in an environment and receives rewards or penalties. It learns a strategy (a policy) that maximises total reward over time. There is no dataset in the usual sense; the agent generates its own experience by trying things.

Examples: game playing, robot control, dynamic pricing, recommendation systems that learn from clicks over time.

Reinforcement learning is powerful but needs a simulator or a lot of live interaction, and is not covered further on this site.

Semi-supervised and self-supervised

Two useful middle grounds you will hear about:

  • Semi-supervised: a small labelled set plus a large unlabelled set. Common when labelling is expensive (medical images).
  • Self-supervised: labels are made from the data itself, such as hiding a word in a sentence and predicting it. This is how large language models are pretrained.

Choosing the family

Ask two questions:

  1. Do I have the answers for past examples? If yes, supervised. If no, unsupervised.
  2. If supervised, is the answer a number or a category? Number means regression, category means classification.
TaskFamilyType
Predict house priceSupervisedRegression
Detect spamSupervisedClassification
Group customers by behaviourUnsupervisedClustering
Compress 100 sensor readings to 3UnsupervisedDimensionality reduction
Learn to play chessReinforcement

Practice

  1. Classify each as regression, classification or clustering: predicting exam marks, predicting pass or fail, grouping students by study habits.
  2. Change the customer data above so there are three obvious groups, set n_clusters=3 and check the labels.