Machine LearningSupervised Learning Comparisons

Classification vs Regression

Question 294 of 303 · Updated

On this page

Classification predicts which category an observation belongs to; regression predicts a numerical quantity. Both are supervised machine-learning tasks: a model learns from examples containing input features and known targets, then predicts targets for new inputs.

The most useful way to distinguish them is to ask: Do you need a label, or do you need a number?

1. What is classification?#

Classification is a supervised-learning task in which the target belongs to a set of classes or categories.

Examples:

  • Email → spam or not spam
  • Transaction → fraudulent or legitimate
  • Image → cat, dog, or bird
  • Customer → likely to churn or likely to stay
  • Support ticket → billing, technical, or account issue

A classifier may produce a class directly, a score, or probabilities for each class. For example:

P(spam | email) = 0.92
P(not spam | email) = 0.08

A decision rule then converts scores or probabilities into a class. With a binary classifier and a threshold of 0.5, the example is labelled spam. The threshold is a business and operating choice, not a universal constant.

Common classification types#

  • Binary classification: exactly two classes, such as fraud / not fraud.
  • Multiclass classification: one of more than two mutually exclusive classes, such as red / green / blue.
  • Multilabel classification: an observation can have several labels simultaneously, such as an image containing both a person and a bicycle.

2. What is regression?#

Regression is a supervised-learning task in which the target is a numerical quantity. It is commonly used for continuous values, such as price, temperature, demand, or delivery duration.

Examples:

  • House details → estimated selling price
  • Weather data → tomorrow's temperature
  • Product history → expected daily demand
  • Route and traffic features → delivery time
  • Customer activity → expected lifetime value

A regression model might return:

Predicted house price = ₹72,00,000
Predicted delivery time = 38.5 minutes
Predicted demand = 1,240 units

The output is an estimate, not a category. Regression is not limited to straight lines: linear models, trees, forests, boosting algorithms, and neural networks can all be used for regression.

3. A simple numerical example#

Imagine an online store wants to use customer and order information.

Task A — Will this order be returned?

The target is one of two categories:

Returned = Yes or No

A classifier predicts a probability of return, say 0.82. If the chosen threshold is 0.60, the order is flagged as likely to be returned.

Task B — How much will this order cost?

The target is a numerical amount:

Order value = ₹2,450

A regression model predicts ₹2,450. If the actual order value is ₹2,700, the prediction error is:

Error = Actual − Predicted
      = ₹2,700 − ₹2,450
      = ₹250

The input features could be similar in both tasks. What changes is the target and the question the business wants answered.

4. Key differences#

Target and output#

  • Classification: predicts a class, label, or class probability.
  • Regression: predicts a numerical value.

Typical evaluation metrics#

Classification metrics include:

  • Accuracy: fraction of predicted labels that are correct.
  • Precision: among predicted positives, how many are truly positive?
  • Recall: among actual positives, how many did the model find?
  • F1 score: harmonic mean of precision and recall.
  • ROC-AUC / PR-AUC: evaluate ranking quality across thresholds.
  • Log loss: evaluates predicted probabilities, penalising confident incorrect predictions.

Regression metrics include:

  • MAE: average absolute prediction error, in target units.
  • MSE: average squared error, which penalises large errors more strongly.
  • RMSE: square root of MSE, in target units.
  • R-squared: compares model fit with a mean-only baseline on the evaluated data.

Choose metrics based on the cost of mistakes and the intended use. Accuracy alone can hide poor minority-class performance; MSE alone may overemphasise large outliers.

Common algorithms#

Some algorithms have separate classifier and regressor variants:

  • Decision trees: DecisionTreeClassifier and DecisionTreeRegressor
  • Random forests: RandomForestClassifier and RandomForestRegressor
  • Gradient boosting: classification and regression estimators
  • Neural networks: classification heads often use sigmoid/softmax; regression heads commonly output numerical values

Other methods are more task-specific. Logistic regression, despite its name, is commonly used for classification. Linear regression is a standard regression method.

Loss functions#

Classification commonly uses cross-entropy / log loss, hinge loss, or task-specific classification objectives. Regression commonly uses squared error, absolute error, Huber loss, or distribution-specific objectives such as Poisson deviance.

The loss function should match the target type, assumptions, and business cost. A training loss is not itself proof of good real-world performance.

5. How do you decide which task you have?#

Start by defining the target you want to predict:

  1. If the desired answer is a named category, formulate a classification problem.
  2. If the desired answer is a numerical quantity whose magnitude matters, formulate a regression problem.
  3. If a numeric field is actually a code for categories (for example, 1 = bronze, 2 = silver, 3 = gold), do not automatically treat it as a regression target. The numbers may only be identifiers.
  4. If a continuous quantity is converted into buckets such as low / medium / high, you have changed the task into classification and discarded some numerical detail.
  5. If the business needs both a probability and an amount, you may need two models or a more specialised formulation.

Example: Predicting whether a customer will default is classification. Predicting the amount of money they may fail to repay is regression. They are related questions, but they have different targets and evaluation criteria.

6. Assumptions and limitations#

Neither classification nor regression is a single algorithm, so there is no one universal set of statistical assumptions for each task. Assumptions depend on the chosen model and objective.

Important considerations for both include:

  • Representative labelled data: training examples should reflect the population and conditions where predictions will be used.
  • Reliable targets: inconsistent labels or inaccurate numerical measurements limit achievable quality.
  • Leakage prevention: features must be available at prediction time. Do not use information created after the outcome.
  • Appropriate validation: use held-out data or cross-validation. Use time-aware splits for future forecasting and group-aware splits when records from the same entity are related.
  • Distribution shift: performance can degrade when customer behaviour, prices, devices, policies, or data pipelines change.

Classification-specific risks include class imbalance, threshold choice, probability miscalibration, and different error costs for false positives and false negatives.

Regression-specific risks include outliers, heteroscedasticity, extrapolation beyond the training range, skewed targets, and negative or physically impossible predictions when the model does not enforce valid output constraints.

7. Python example with scikit-learn#

The estimator choice follows the target type. The examples below use the same feature matrix conceptually, but each task needs its own target.

Classification#

PYTHON
from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import classification_report # y_class contains categories such as 0/1 or "spam"/"not_spam" classifier = RandomForestClassifier( n_estimators=200, random_state=42, class_weight="balanced" ) classifier.fit(X_train, y_class_train) class_predictions = classifier.predict(X_test) class_probabilities = classifier.predict_proba(X_test) print(classification_report(y_class_test, class_predictions))

Use predict_proba when probability estimates are needed and the estimator supports them. Select a decision threshold using validation data and the cost of false positives and false negatives. Class weighting is one possible response to imbalance, not a substitute for checking per-class metrics.

Regression#

PYTHON
from sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_absolute_error, root_mean_squared_error, r2_score # y_value contains numerical targets such as price or delivery time regressor = RandomForestRegressor( n_estimators=200, random_state=42 ) regressor.fit(X_train, y_value_train) value_predictions = regressor.predict(X_test) print("MAE:", mean_absolute_error(y_value_test, value_predictions)) print("RMSE:", root_mean_squared_error(y_value_test, value_predictions)) print("R-squared:", r2_score(y_value_test, value_predictions))

The examples assume the train/test splits and preprocessing have already been prepared correctly. Fit preprocessing only on training data, preferably inside a scikit-learn pipeline, and evaluate on untouched test data.

8. Production guidance#

Before deploying either type of model:

  • Define the prediction target, unit or class taxonomy, prediction time, and decision owner.
  • Establish a simple baseline and compare candidate models on representative validation data.
  • Choose metrics tied to business impact rather than selecting a model by one headline score.
  • For classifiers, monitor class distribution, precision/recall by important segment, threshold outcomes, and probability calibration where probabilities drive decisions.
  • For regressors, monitor MAE/RMSE, residual patterns, error by segment, and the frequency of invalid or out-of-range predictions.
  • Track input quality, missingness, feature freshness, prediction latency, and changes in the target distribution.
  • Re-evaluate when labels mature and when the population or business process changes.

A model's class probability is not automatically a calibrated probability, and a low offline regression error does not guarantee acceptable performance after deployment. Keep monitoring and a safe fallback or human-review path for high-impact decisions.

Key takeaway#

Classification answers “Which class?”; regression answers “How much?” Choose based on the target the business needs, not merely on which algorithm is familiar. Classification is evaluated with metrics such as precision, recall, F1, and log loss; regression is evaluated with metrics such as MAE, RMSE, and R-squared. Validate both on data that represents real prediction conditions.

Interview answer: Classification predicts a discrete category or class probability, while regression predicts a numerical quantity. For example, predicting whether a transaction is fraudulent is classification; estimating the amount of fraud loss is regression. The target type determines the task, the model output, and the appropriate evaluation metrics.

Related questions

Explore other topics:Deep LearningMLOps