What is the difference between classification and regression in Supervised Learning?
Updated Feb 20, 2026
Short answer
The key difference is the target a model learns to predict. Classification predicts a discrete category, while regression predicts a continuous numerical value. Both learn from labeled examples, but they optimize for different kinds of outputs.
Deep explanation
In supervised learning, a model learns a relationship between input data (features) and a known answer (label). The main question that separates classification from regression is: What type of answer are we asking the model to produce?
Classification answers "which group?" while regression answers "how much?"
Classification: predicting categories
Classification is used when the output belongs to a fixed set of classes. The model learns boundaries that separate one category from another.
Examples of classification problems:
- Predict whether an email is
spamornot_spam. - Identify whether an image contains a
cat,dog, orbird. - Predict whether a customer will
churnorstay.
The output is usually a class label, but many classification models also produce probabilities.
For example:
prediction = model.predict(["You won a free prize!"])
# Output:# "spam"A classification model might internally estimate:
spam: 0.92not_spam: 0.08Then it chooses the class with the highest probability.
Regression: predicting continuous values
Regression is used when the output is a number that can vary across a range.
Examples of regression problems:
- Predict the price of a house.
- Estimate tomorrow's temperature.
- Forecast monthly sales revenue.
- Predict the delivery time for an order.
The model learns a function that maps inputs to a numeric value.
estimated_price = model.predict([ 3, # bedrooms 1500, # square feet 10 # age of house])
# Output:# 250000The answer is not a category. It is a measurable quantity.
Visual difference
Comparing classification and regression
| Aspect | Classification | Regression |
|---|---|---|
| Prediction type | Category or class | Continuous number |
| Example output | approved, rejected | 45200 |
| Common algorithms | Logistic regression, decision trees, neural networks | Linear regression, regression trees, neural networks |
| Common metrics | Accuracy, precision, recall, F1 score | Mean absolute error, mean squared error, R² |
How training differs
Although both use labeled data, the model measures mistakes differently.
For classification:
- A prediction is compared against the correct class.
- The model learns to reduce incorrect classifications.
- The decision boundary between classes is important.
For regression:
- A prediction is compared against the actual number.
- The model learns to reduce the distance between predicted and true values.
- The size of the error matters.
For example, predicting a house price as $300,000 when the actual price is $310,000 is a smaller mistake than predicting $100,000. Regression models care about this numerical gap.
The algorithm family does not always determine the task; the output you need determines whether it is classification or regression. A decision tree can perform both tasks: a classification tree predicts categories, while a regression tree predicts numbers.
A simple interview rule: if the answer is a label, think classification; if the answer is a quantity, think regression.
A common nuance: logistic regression
A frequent beginner confusion is the name logistic regression. Despite the word "regression," it is primarily a classification algorithm.
It predicts the probability of belonging to a class:
probability = logistic_model.predict_proba([ customer_data])
# Example output:# [0.15, 0.85]The probability might represent an 85% chance that a customer will churn. The final prediction is still a category such as churn or not_churn.
Always identify the type of prediction, not just the algorithm name, when classifying a machine learning problem.
Real-world example
Imagine an online shopping company wants to use machine learning.
For fraud detection, the company has historical transactions labeled fraud or legitimate. A classification model learns patterns such as unusual locations, spending amounts, and transaction timing, then predicts the category of a new transaction.
For revenue forecasting, the company uses past sales data to predict next month's revenue amount. A regression model learns from previous trends and outputs a number.
fraud_result = fraud_classifier.predict(transaction)next_month_sales = sales_regressor.predict(month_data)The same company can use both approaches because the business questions are different: "Is this transaction fraudulent?" is classification, while "How much will we sell?" is regression.
Common mistakes
- * **Output confusion** - Treating every prediction problem as regression or classification without checking whether the target is a category or a number.
- * **Algorithm confusion** - Assuming an algorithm's name defines the task
- for example, `logistic regression` is commonly used for classification.
- * **Ignoring probabilities** - Forgetting that classification models often predict confidence scores before selecting a final class.
- * **Wrong metrics** - Using accuracy for price prediction or mean squared error for a class prediction leads to misleading evaluation.
- * **Overlooking data labels** - Training requires correct historical answers
- poor labels create unreliable supervised learning models.
Follow-up questions
- Can a machine learning model perform both classification and regression?
- What is the difference between classification and clustering?
- Why is linear regression not used for classification?
- What metrics are commonly used for classification problems?
- What metrics are commonly used for regression problems?