Classification vs Regression in Machine Learning
Classification predicts a category and regression predicts a number. See the differences, examples, metrics and a tiny Python demo of both.
Short answer: the difference between classification and regression in machine learning is the type of answer the model gives. Classification predicts a category, such as spam or not spam. Regression predicts a number, such as a house price or tomorrow's temperature. Both are kinds of supervised learning, where the model learns from examples with known answers.
What Is Classification?
Classification puts an item into one of a fixed set of classes. With two classes it is called binary classification (spam or not spam). With more, it is multi-class (is this photo a cat, a dog or a bird?). The output is a label, often together with a probability.
What Is Regression?
Regression predicts a continuous number. The answer can be any value in a range, not one of a few labels: a price, a temperature, the minutes a delivery will take.
Classification vs Regression: Side by Side
Classification | Regression | |
|---|---|---|
Output | A category (label) | A number |
Example question | Is this email spam? | How much will this house sell for? |
Typical algorithms | Logistic regression, decision trees, k-nearest neighbours | Linear regression, decision trees, random forests |
Common metrics | Accuracy, precision, recall | Mean absolute error, mean squared error |
Some algorithms can do both, which is why the names overlap. Despite its name, logistic regression is used for classification.
How Do You Know Which One You Need?
Ask: “Is the answer a category or a number?”
“Will this customer leave?” gives yes or no, so it is classification.
“How many items will we sell next week?” gives a count, so it is regression.
“Is this tumour image benign or not?” is classification.
“What will the temperature be at noon?” is regression.
A tricky case: ages. You can predict an exact age (regression) or put people into groups such as child, adult and senior (classification). You choose based on what the decision needs.
A Tiny Example in Python
Both ideas in plain Python, with no libraries:
# Regression: predict a NUMBER (exam score) from hours studied
hours = [1, 2, 3, 4, 5]
score = [52, 58, 65, 71, 78]
n = len(hours)
mean_x = sum(hours) / n
mean_y = sum(score) / n
slope = (sum((x - mean_x) * (y - mean_y) for x, y in zip(hours, score))
/ sum((x - mean_x) ** 2 for x in hours))
intercept = mean_y - slope * mean_x
print("Predicted score for 6 hours:", round(slope * 6 + intercept, 1))
# Classification: predict a LABEL (pass or fail) with the nearest example
examples = [(1, "fail"), (2, "fail"), (4, "pass"), (5, "pass")]
def classify(h):
return min(examples, key=lambda e: abs(e[0] - h))[1]
print("Label for 3.5 hours:", classify(3.5))The first part fits a straight line and predicts a score of about 84.3 for 6 hours. The second returns the label pass for 3.5 hours because the closest example is 4. Real projects use a library such as scikit-learn, as in the chapter your first model with scikit-learn.
Common Mistakes
Using accuracy on a regression problem. Use an error metric instead.
Treating a number-like label (such as class 1, 2, 3) as a quantity to regress.
Judging a classifier by accuracy alone when one class is rare, since a model that always says “no” can look accurate.
Confusing logistic regression with regression.
Key Takeaway
Classification predicts a category; regression predicts a number. Ask what form the answer should take and the choice is usually clear. For the bigger picture, see types of machine learning.
Ready to start? Understand how machines learn from data, in plain language, before you write any model code. Begin with the free course How AI Works: Foundations for Everyone.
Related articles
More in Machine Learning
Training vs Validation vs Test Data
Why machine learning data is split into training, validation and test sets, what each is for, how to split it and how to avoid data leakage.
3 min readNov 13, 2026Overfitting vs Underfitting, Explained Simply
What overfitting and underfitting mean, how to spot each from training and test error, and how to fix them, with a small runnable example.
4 min readNov 8, 202610 Real-World Uses of Deep Learning
Deep learning powers speech recognition, translation, recommendations, chatbots and more. See 10 real uses and the kind of model behind each.
4 min readNov 5, 2026How Much Maths Do You Need for Machine Learning?
An honest answer by goal: how much linear algebra, probability, statistics and calculus you need for machine learning, what to skip at first, and how to learn it alongside coding.
4 min readNov 3, 2026How Does a Neural Network Work? A Simple Explanation
Neurons, weights, bias, layers and how a network learns from its mistakes, explained in plain words with a handwritten-digit example and no heavy maths.
4 min readOct 30, 2026Types of Machine Learning: Supervised, Unsupervised and Reinforcement
Machine learning comes in three main types. See how supervised, unsupervised and reinforcement learning differ, with everyday examples and a comparison table.
4 min readOct 30, 2026
Comments
Sign in to join the discussion.

