What is the difference between classification and regression problems?
Learn the difference between classification and regression in machine learning, with examples, metrics, and models for data science interviews.
Expected Interview Answer
Classification and regression are both supervised learning tasks, but classification predicts a discrete category or label while regression predicts a continuous numeric value.
In classification the output belongs to a fixed set of classes, such as spam or not spam, and models are evaluated with metrics like accuracy, precision, recall and F1. In regression the output is a real number, such as a house price or temperature, and models are evaluated with metrics like mean absolute error, mean squared error and R-squared. The distinction is driven by the nature of the target variable, and the same algorithm family, such as decision trees or neural networks, often has both a classification and a regression variant.
- Guides the choice of loss function and metrics
- Determines the right model variant to use
- Clarifies how to frame the business problem
- Shapes how outputs are interpreted and acted on
- Prevents mismatched evaluation of results
AI Mentor Explanation
Classification is deciding whether a delivery is out or not out, a label from a fixed set. Regression is predicting the exact number of runs a batter will score, a continuous value. Same match, but one question sorts events into buckets while the other estimates a precise quantity along a scale.
Step-by-Step Explanation
Step 1
Inspect the target variable
Check whether the value you predict is a category or a continuous number.
Step 2
Frame the task
If discrete labels, it is classification; if a real-valued quantity, it is regression.
Step 3
Pick a suitable model
Choose the classification or regression variant, such as logistic vs linear regression.
Step 4
Select the loss and metrics
Use cross-entropy and accuracy or F1 for classification; MSE, MAE or R-squared for regression.
Step 5
Evaluate appropriately
Interpret results with metrics matched to the task, never accuracy for a regression output.
What Interviewer Expects
- Correct definition based on the target variable type
- Concrete examples of each task
- Knowledge of appropriate evaluation metrics
- Awareness that algorithms often have both variants
- Understanding that both are supervised learning
Common Mistakes
- Confusing binary classification with regression because both output numbers
- Using accuracy to evaluate a regression model
- Treating an ordinal or ID number as a continuous target
- Forgetting that logistic regression is classification despite its name
- Choosing a loss function mismatched to the task
Best Answer (HR Friendly)
“Classification predicts which category something falls into, like spam or not spam, while regression predicts an actual number, like a price or a temperature. The key difference is whether the answer is a label or a quantity, and that decides which model and evaluation you use.”
Code Example
from sklearn.linear_model import LogisticRegression, LinearRegression
# Classification: predict a discrete label (0 or 1)
clf = LogisticRegression()
clf.fit(X_train, y_class) # y_class in {0, 1}
label = clf.predict(X_new) # -> array of class labels
# Regression: predict a continuous value
reg = LinearRegression()
reg.fit(X_train, y_price) # y_price is a real number
price = reg.predict(X_new) # -> array of numeric predictionsFollow-up Questions
- Which metrics would you use to evaluate each task?
- Can a regression model be turned into a classifier?
- What is logistic regression and why is it classification?
- How do you handle a multi-class classification problem?
- What is the difference between ordinal and continuous targets?
MCQ Practice
1. Predicting whether an email is spam or not spam is an example of:
The target is a discrete label (spam or not), which makes it a classification task.
2. Which metric is appropriate for evaluating a regression model?
Mean squared error measures the average squared difference between predicted and actual continuous values.
3. Despite its name, logistic regression is used for:
Logistic regression outputs class probabilities and is a classification algorithm, not a continuous-value predictor.
Flash Cards
Classification vs regression: core difference? — Classification predicts discrete categories; regression predicts continuous numeric values.
Example of classification — Predicting whether a transaction is fraudulent or legitimate.
Example of regression — Predicting a house price or tomorrow's temperature.
Metrics for classification — Accuracy, precision, recall, F1 score, ROC-AUC.
Metrics for regression — Mean absolute error, mean squared error, RMSE, R-squared.