☰ Machine Learning Tutorial Menu

Supervised, Unsupervised and Reinforcement Learning

Written by CSA mentors · Updated 26 Sept 2026 · 5 min read


The most common mistake in our first-week assignments isn't a coding error. It's a student running k-means on a churn dataset that already has a churn column, or trying to "predict" segments that nobody has ever labelled. Before you pick an algorithm you need one answer: do your rows come with the answer attached? That single question decides the toolkit, and a churn project and a segmentation project use different tools even when both start from the same customer table.

Supervised: the answer is in the table

Every training row carries a known outcome, the label, and the model learns the mapping from features to it. Two flavours:

Sub-typeLabel looks likeExamplesTypical algorithms
RegressionA numbernext month's electricity load, house price in DHA, delivery minuteslinear regression, gradient boosting
ClassificationA categoryfraud / not fraud, will churn / will stay, loan grade A/B/Clogistic regression, decision trees, random forest, SVM

The label is usually the expensive bit. A bank's fraud team may wait months for enough confirmed cases before a classifier can be trained, and we've seen projects stall for exactly that reason.

Unsupervised: no answer column at all

Here the algorithm hunts for structure on its own. It might find groups of similar rows (clustering), a compact summary of many columns (dimensionality reduction), or rows that look unlike everything else (anomaly detection). The catch is that the output needs a human to read it. k-means hands you "cluster 2" and it's your job to notice that cluster 2 is "students who order late at night".

Left: labelled points with a learned decision boundary. Right: unlabelled points grouped into three clusters

Reinforcement: learning by being rewarded

An agent takes actions in an environment, gets a reward, and adjusts to earn more of it over time. No labelled rows, only feedback after each move. It runs game-playing systems and some dynamic-pricing engines, but it needs a safe place to experiment, and most Pakistani businesses can't afford to let an algorithm poke their live pricing. Recognise it in interviews; don't start your career with it.

An agent sends an action to the environment and receives a reward and a new state in a loop

The three families side by side

SupervisedUnsupervisedReinforcement
Inputfeatures + labelsfeatures onlystate + reward signal
Goalpredict the label for new rowsdiscover structurechoose actions that maximise reward
How you check itcompare predictions with held-out labelshuman judgement, silhouette scoretotal reward over episodes
Business question"Which of these will X?""What kinds of these exist?""What should I do next?"
Data neededhundreds to millions of labelled rowsunlabelled rowsa simulator or a live system you can safely poke

Sort four real requests, then fit something tiny

Imagine you're the analyst at a mobile wallet and four requests land in one morning. Family first, algorithm later.

RequestLabel available?Label typeFamily
Predict which agents will stop transacting next monthYes (past inactivity)categorysupervised, classification
Estimate cash-out volume per agent next weekYes (past volumes)numbersupervised, regression
Group agents into behaviour types for a marketing planNo-unsupervised, clustering
Decide the cash-back offer each user sees to maximise usageOnly reward after showing it-reinforcement (or an A/B test first)

Now the smallest supervised classifier we can do by hand. Six agents, one feature (transactions last month), one label (active next month).

AgentTxns last monthActive next month?
A5No
B12No
C30Yes
D18Yes
E9No
F45Yes

The simplest classifier is a threshold. Sort by transactions: 5 (No), 9 (No), 12 (No), 18 (Yes), 30 (Yes), 45 (Yes). Any cut between 12 and 18 separates the classes perfectly, so take the midpoint 15. Your "model" reads predict active if transactions > 15, and a new agent with 14 transactions is predicted inactive. Real data overlaps, which is why later lessons bring in probabilities, but the shape of the task is identical.

# run locally
from sklearn.tree import DecisionTreeClassifier
from sklearn.cluster import KMeans

X = [[5], [12], [30], [18], [9], [45]]
y = [0, 0, 1, 1, 0, 1]                        # supervised: label present
clf = DecisionTreeClassifier(max_depth=1).fit(X, y)
print(clf.predict([[14], [20]]))              # -> [0 1]

km = KMeans(n_clusters=2, n_init=10, random_state=0).fit(X)   # unsupervised: no y
print(km.labels_)                             # group ids, meaning is yours to decide

Turning "we want AI" into three projects: A Faisalabad textile exporter asked us for "AI to improve sales". We split it into three real pieces of work. A regression to forecast monthly yarn demand per buyer (supervised). A clustering of 400 buyers by order size, frequency and payment delay (unsupervised). A classifier for which invoices will be paid more than 30 days late (supervised). Each got its own data, metric and owner, and the finance and sales heads could sign off on each one separately. The vague request was the real problem, not the maths.

Quick recap

  • Ask "is there a label?" before anything else.
  • Supervised predicts a known target, regression for numbers and classification for categories.
  • Unsupervised finds structure, and a person has to interpret it.
  • Reinforcement learns actions from reward and is rarely the first thing a business should try.
  • One vague request usually hides two or three well-defined ML problems.

Homework

  1. Label each as regression, classification, clustering or reinforcement: predicting a car's resale price on PakWheels; grouping Careem riders by travel habits; deciding whether a CNIC scan is readable; choosing ad bids in real time.
  2. Add agent G with 16 transactions who went inactive. Does one threshold still separate the classes? What would you do about it?
  3. Write one sentence describing the "label" for a K-Electric project that predicts transformer failures.

Lesson 2 of 18

Sign in to track your progress and earn learning points for every lesson you finish.