☰ 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-type | Label looks like | Examples | Typical algorithms |
|---|---|---|---|
| Regression | A number | next month's electricity load, house price in DHA, delivery minutes | linear regression, gradient boosting |
| Classification | A category | fraud / not fraud, will churn / will stay, loan grade A/B/C | logistic 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".
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.
The three families side by side
| Supervised | Unsupervised | Reinforcement | |
|---|---|---|---|
| Input | features + labels | features only | state + reward signal |
| Goal | predict the label for new rows | discover structure | choose actions that maximise reward |
| How you check it | compare predictions with held-out labels | human judgement, silhouette score | total reward over episodes |
| Business question | "Which of these will X?" | "What kinds of these exist?" | "What should I do next?" |
| Data needed | hundreds to millions of labelled rows | unlabelled rows | a 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.
| Request | Label available? | Label type | Family |
|---|---|---|---|
| Predict which agents will stop transacting next month | Yes (past inactivity) | category | supervised, classification |
| Estimate cash-out volume per agent next week | Yes (past volumes) | number | supervised, regression |
| Group agents into behaviour types for a marketing plan | No | - | unsupervised, clustering |
| Decide the cash-back offer each user sees to maximise usage | Only 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).
| Agent | Txns last month | Active next month? |
|---|---|---|
| A | 5 | No |
| B | 12 | No |
| C | 30 | Yes |
| D | 18 | Yes |
| E | 9 | No |
| F | 45 | Yes |
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
- 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.
- Add agent G with 16 transactions who went inactive. Does one threshold still separate the classes? What would you do about it?
- 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.
