What is the difference between classification and regression?
Classification and regression are the two main kinds of supervised learning. Classification predicts a category, such as spam or not spam. Regression predicts a number on a continuous scale, such as a price or a temperature. The difference lies in the target the model learns to predict, not in the inputs or the model family.
The choice decides the rest of the setup: the output layer, the loss function, and the metrics. Regression models usually end in a linear output trained with mean squared error. Classifiers end in a sigmoid or softmax trained with cross-entropy. Credit scoring, medical diagnosis, and image recognition are classification problems. Demand forecasting, price estimation, and predicting a patient's length of stay are regression.
Key ideas
- Classification predicts a category; regression predicts a continuous number.
- The task type comes from the target variable, not from the input features.
- Regression usually uses a linear output with MSE or MAE loss.
- Binary classification uses a sigmoid output with binary cross-entropy.
- Multi-class classification uses a softmax output with categorical cross-entropy.
- A classifier's threshold trades false positives against false negatives.
Common questions
Is logistic regression a classification or regression method?
It is a classification method. The name comes from the fact that it fits a linear regression to the log-odds of the positive class, then passes the result through a sigmoid to get a probability. Thresholding that probability gives the class.
Can one problem be framed as either classification or regression?
Often, yes. Age can be predicted as a number or as age brackets, and sentiment can be a score from −1 to 1 or the classes positive, neutral, and negative. Regression keeps the order and distance between values. Classification is easier to interpret when only a few outcomes lead to different decisions.
Which metrics are used for classification and for regression?
Regression is measured with MAE, RMSE, or R², which compare predicted and true numbers. Classification uses accuracy, precision, recall, F1 score, and ROC AUC. On imbalanced data accuracy can mislead, because a model that always predicts the majority class scores well.
Can the same algorithm do both classification and regression?
Most can. Decision trees, random forests, gradient boosting, k-nearest neighbors, and neural networks all come in classifier and regressor versions. The model structure stays the same, while the output and the loss change: a leaf predicts a mean instead of a majority class, or a network ends in a linear unit instead of a softmax.
Related explainers
- Loss Functions — How networks measure their mistakes
- Softmax, Logits & Temperature — Turning raw scores into probabilities
- Model Evaluation & Metrics — Precision, recall, F1, ROC curves, and regression metrics
- The Perceptron — The simplest neural network — one neuron, one decision boundary
- Decision Trees & Splitting — Recursive partitioning, Gini impurity, and pruning
- Class Imbalance & Resampling — SMOTE, class weights, and metrics beyond accuracy
References
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning" (ISLR), chapters 3 and 4
- Goodfellow, Bengio & Courville (2016), "Deep Learning", chapter 5: Machine Learning Basics
- Zhang et al., "Dive into Deep Learning", Linear Regression
- Bishop (2006), "Pattern Recognition and Machine Learning"
Last updated