Start learning

Supervised and Unsupervised Learning

Lesson 3. About 10 minutes, with a video walkthrough.

In supervised learning every example comes with the correct answer, and the model learns to predict it. In unsupervised learning there are no answers, and the model finds structure in the data on its own.

Your Path Through This Lesson

0 of 5 done

By the End of This Lesson You Can
  • Decide from your data whether a problem is supervised or unsupervised.
  • Tell regression from classification at a glance.
  • Run a tiny clustering example and read its output correctly.

The One Question That Decides It

Look at your dataset and ask: do I have the answer column?

  • Hours and marks for each student: yes, you have the marks. That's supervised.
  • Thousands of customers and what they bought, but no column saying which "type" of customer each one is: no answer column. That's unsupervised.

The answer column has many names: target, label, output, dependent variable, or just . They all mean the same thing.

Supervised Learning

It's called supervised because the answers act like a teacher checking the model's work during training. The model guesses, compares its guess with the real answer, and corrects itself.

Supervised learning splits into two kinds, depending on what type of answer you're predicting.

Regression: Predicting a Number

The target is a continuous number: something you can measure on a scale.

  • Marks from hours studied
  • House price from size and location
  • Tomorrow's temperature
  • Delivery time in minutes

Classification: Predicting a Category

The target is one of a fixed set of groups.

  • Pass or fail (two classes, binary classification)
  • Spam or not spam
  • Which digit, 0 to 9, is in an image (ten classes, multi-class classification)
  • Whether a loan will be repaid
Regression predicts a number on a continuous scale. Classification predicts which group an example belongs to.
Regression predicts a number on a continuous scale. Classification predicts which group an example belongs to.
Tip

A quick test: if the answer makes sense with a decimal point ("58.5 marks", "2.3 crore taka"), it's regression. If it's a name or a group ("pass", "spam", "cat"), it's classification. Careful with numbers that are really categories: a postcode like 1205 is a label, not a quantity.

Unsupervised Learning

Here you only have the inputs, , with no . The model's job is to find patterns nobody pointed out.

Clustering: Finding Groups

Put similar examples together. A shop might cluster its customers into "students who buy cheap snacks late at night", "families who shop on Fridays" and so on, without anyone defining those groups first. You'll meet k-means and DBSCAN for this later.

Dimensionality Reduction: Fewer Columns, Same Story

When data has hundreds of columns, many of them repeat the same information. Methods like PCA squeeze them into a few new columns that keep most of the information. It makes data easier to plot and faster to train on.

A Tiny Clustering Example

Here are six points with no labels. Can the model find the two obvious groups?

python
from sklearn.cluster import KMeans

X = [[1, 1], [1.5, 2], [1, 1.5],     # three points near (1, 1.5)
     [8, 8], [8.5, 9], [9, 8]]        # three points near (8.5, 8.5)

kmeans = KMeans(n_clusters=2, n_init=10, random_state=0)
labels = kmeans.fit_predict(X)
print(labels)
Output
[1 1 1 0 0 0]

The first three points got one label and the last three got the other. Nobody told the model which point belongs where. It found the groups from the distances alone.

Watch Out

The numbers 0 and 1 are just names for the groups, not an order or a score. You might see [0 0 0 1 1 1] instead, and that means exactly the same grouping.

Comparing the Two

Supervised Unsupervised
Do we have ? Yes, every row is labelled No labels
Goal Predict the label for new data Discover structure
Main tasks Regression, classification Clustering, dimensionality reduction
How do we check it? Compare predictions with true answers Harder: no answer key to compare with
Algorithms in this course Linear and logistic regression, trees, SVM, KNN, Naive Bayes K-means, hierarchical clustering, DBSCAN, PCA
Note

There are more families too. Semi-supervised learning uses a few labelled rows plus many unlabelled ones. Reinforcement learning learns by trial and error from rewards, which is how game-playing agents learn. We'll stick to the two big ones for now.

Try It Yourself

Label each task as regression, classification or clustering: (1) predict a phone's resale price, (2) decide whether a photo shows a mango or a banana, (3) group news articles by topic with no topic labels, (4) predict how many units of rice will sell next week. Answers: regression, classification, clustering, regression.

The Key Idea

Ask one question: do I have the answer column? Yes means supervised. No means unsupervised.

Summary

  • Supervised = you have labels. Predict a number (regression) or a category (classification).
  • Unsupervised = no labels. Find groups (clustering) or compress features (dimensionality reduction).
  • Next: before training any supervised model, you must hide some data from it. That's the train and test split.