Classification vs Regression

    Yash Kabra4 min readUpdated

    Both classification and regression are supervised learning, where a model learns from labelled examples. The difference is the kind of answer they predict. Classification predicts a category — spam or not spam, pass or fail. Regression predicts a number — a price, a temperature, a score. The question "is my answer a label or a quantity?" tells you which one you need.

    Classification: predicting a category

    In classification, the output is one of a fixed set of classes. The classes can be two (binary) or more (multi-class):

    • Binary: will this customer churn — yes or no?
    • Multi-class: which of three flower species is this?

    The model outputs a class, and often a probability for each class too. Classification underlies spam filters, medical screening tools, and image labelling. For more on labelled learning generally, see supervised vs unsupervised learning.

    # Classification: predict a category (flower species).
    from sklearn.datasets import load_iris
    from sklearn.model_selection import train_test_split
    from sklearn.linear_model import LogisticRegression
    
    X, y = load_iris(return_X_y=True)   # y holds category labels
    X_train, X_test, y_train, y_test = train_test_split(
        X, y, test_size=0.25, random_state=0
    )
    
    model = LogisticRegression(max_iter=200)
    model.fit(X_train, y_train)
    
    # Output is a class label, e.g. 0, 1, or 2.
    print(model.predict(X_test[:3]))
    

    Regression: predicting a number

    In regression, the output is a continuous value. Instead of "which class", the question is "how much" or "how many":

    • How much will this house sell for?
    • How many units will we sell next month?
    • What will tomorrow's temperature be?
    # Regression: predict a number (a continuous value).
    import numpy as np
    from sklearn.linear_model import LinearRegression
    
    # Hours studied -> exam score.
    X = np.array([[1], [2], [3], [4], [5]])
    y = np.array([35, 50, 60, 72, 85])
    
    model = LinearRegression()
    model.fit(X, y)
    
    # Output is a number, not a category.
    print(round(model.predict([[6]])[0], 1))   # e.g. about 96.5
    

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses

    How each is measured

    Because the answers differ, so do the scorecards.

    • Classification is judged by how often it is right: accuracy (fraction correct), plus precision and recall when classes are imbalanced or some errors cost more than others.
    • Regression is judged by how far off the numbers are: mean absolute error (average size of the miss) or mean squared error (which punishes big misses more).

    Using the wrong metric hides real problems. Accuracy on a regression task makes no sense, and an error distance on a category makes no sense either.

    How to tell which you need

    Look at the column you are trying to predict:

    • A category, with a fixed set of distinct values (yes/no, A/B/C) → classification.
    • A number that can take many values on a scale (price, weight, time) → regression.

    A useful check: if averaging two valid answers gives a meaningless result, it is classification. Halfway between "spam" and "not spam" means nothing; halfway between two prices is a perfectly good price.

    Common mistakes

    • Treating numeric labels as a quantity. A category coded as 1, 2, 3 is still a category, not a number to average. Use classification.
    • Using accuracy for regression. Regression outputs rarely match exactly; measure the size of the error instead.
    • Ignoring class imbalance. If 95% of cases are one class, a model that always guesses it scores 95% accuracy while being useless. Check precision and recall.
    • Forcing a number into bins unnecessarily. Converting a quantity into categories throws away information unless the problem genuinely needs categories.

    FAQ

    Can one problem be both? You can reframe some problems. Predicting an exact price is regression; predicting a price band (low/medium/high) is classification. The framing depends on what decision the output supports.

    Are the algorithms different? Some algorithms do only one; many, like decision trees, have both a classifier and a regressor version. The workflow in build your first ML model applies to both.

    Which is more common for beginners? Classification examples are very common in tutorials, but both are everyday tasks. Learn both; the difference is mostly the output and the metric.

    Keep learning

    Explore the full AI & machine learning hub for more guides, or join the waitlist for our structured Artificial Intelligence course at Infoplanet, Jalgaon, to practise both classification and regression with mentor support.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses
    Yash Kabra

    Founder, Atlee Technologies

    Yash Kabra is the founder of Atlee Technologies, a product studio that ships SaaS products end-to-end. He owns products from strategy through launch and growth — including Infoplanet, TrackRise and Perqee — and teaches AI, Machine Learning and Data Science at Infoplanet with a focus on how these tools are used to build real products.

    Related guides