Machine LearningLesson 6 of 22

Supervised vs Unsupervised Learning

Supervised learning means you have labels. You show the model houses with their prices, and it learns to predict price for new houses. Unsupervised means you have no labels, and the model finds hidden groups, like clustering customers by buying habits.

Supervised learning means you have labels. You show the model houses with their prices, and it learns to predict price for new houses. Unsupervised means you have no labels, and the model finds hidden groups, like clustering customers by buying habits.

Supervised splits into classification (predict a category, like spam or not spam) and regression (predict a number, like price). Unsupervised is mostly clustering and dimensionality reduction. Choosing the wrong type is a common beginner error.

If you have a target column, you are supervised. If you only have features and want to find patterns, you are unsupervised. Everything from evaluation to deployment changes based on this choice.

How to tell which you need

Ask: do I have a column I want to predict? If yes, supervised. If you just want to group similar rows, unsupervised. Mix them and your metrics will be meaningless.

PYTHON
# supervised: X + y -> model
# unsupervised: X -> clusters
# y is None for unsupervised

Labels are expensive

Supervised needs labeled data, which often requires humans to annotate. Unsupervised can run on raw data but its results are harder to evaluate. This tradeoff decides project cost.

PYTHON
# classification: y = ["spam","ham"]
# regression: y = [200000, 350000]
# clustering: no y

Syntax

PYTHON
# Supervised
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_train, y_train)  # y exists

# Unsupervised
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)  # no y

The “I have no labels so I will make them with clustering then classify” trap

Beginners cluster data to create labels, then train a classifier on those labels and report 99% accuracy. This is circular and proves nothing — you are predicting your own clusters. Reddit r/MachineLearning flags this monthly.

PYTHON
# Don't: kmeans.fit(X); y_fake = kmeans.labels_; clf.fit(X, y_fake)  # circular

Good to know

  • Supervised needs labels, unsupervised finds hidden groups.
  • Classification predicts categories, regression predicts numbers.
  • Choosing the wrong type makes evaluation meaningless.

Keep building your ML models

Copy the code, run it locally with pip install scikit-learn pandas, and continue to the next lesson.

→ Next: Linear Regression: Your First Model