Lesson · ⏱ 6 min read

🎯 Two kinds of prediction: regression and classification

EnglishHinglish

🏠 Real-life example

A Swiggy app answers two different kinds of questions. 'How many minutes until delivery?' has a number as its answer: that's regression. 'Will this order be late: yes or no?' puts the order in a category: that's classification.

💡 In simple words

Regression predicts a continuous number, such as price, temperature or delivery time. Linear regression, the classic starting point, draws the best straight-line relationship between features and the number. Classification predicts a category, such as spam/not spam, fraud/genuine, or which of 10 product types. Logistic regression, despite its name, is a simple classification model that outputs a probability. Decision trees can do both. Always start with these simple models before trying anything complex.

🪜 Step by step

  1. Ask what the answer looks like. A number (price, delivery days) means regression. A category (spam or not, which product type) means classification.
  2. For regression, start with linear regression; measure error in real units (MAE: off by ₹1,200 on average).
  3. For classification, start with logistic regression; it gives a probability you can threshold.
  4. Compare with a dumb baseline: always predict the average, or always the most common class.
  5. Then try stronger models (random forest, gradient boosting) and keep the simplest one that clearly wins.

🔑 Key terms

Regression
Predicting a number, e.g. house price.
Classification
Predicting a category, e.g. spam or not.
Baseline
The simplest possible prediction, which your model must beat.

👀 See it in action

python
from sklearn.linear_model import LinearRegression, LogisticRegression

reg = LinearRegression().fit(X_train, delivery_minutes)   # regression
clf = LogisticRegression().fit(X_train, is_late)           # classification

reg.predict(X_new)          # → [32.5] minutes
clf.predict_proba(X_new)    # → [[0.8, 0.2]] → 20% chance of being late

Same features, two different questions, two different model types.

⚠️ Common mistakes to avoid

  • Treating categories as numbers, like city codes 1, 2, 3, so the model thinks city 3 is 'more' than city 1. Use one hot encoding.
  • Using accuracy for regression or MAE for classification. Each type has its own metrics.

✅ Quick check

Predicting tomorrow's number of website visitors is…

  1. Regression
  2. Clustering
  3. Classification
Show answer

A. Regression: The answer is a number (a count of visitors), so it's regression.

🙋 Questions learners ask

Why is it called logistic 'regression' if it classifies?

Historical naming: it predicts a number, the probability, which is then turned into a class with a threshold.

Can one model do both?

Many algorithms have both versions, like decision trees and gradient boosting. You pick the version that matches your target.

📌 Remember

Number → regression. Category → classification. Start simple.

📖 Words from this lesson (AI dictionary)

Learn this as part of a full course

Track your progress, take the quick checks and follow the lessons in the right order. This lesson is part of:

AI Foundations Path · ML Engineer

Continue in the course