classification

classification vs regression
Artificial Intelligence, Featured Articles

Classification vs Regression in Machine Learning

The difference between classification vs regression comes down to the answer you want. Classification predicts a category, such as “spam” or “not spam.” Regression predicts a number on a continuous scale, such as a house price or tomorrow’s temperature. Both belong to supervised learning, so both learn from labeled examples. This guide explains how the two tasks differ, which algorithms and metrics fit each one, and how to decide which task your own problem needs. If you are new to the field, read What Is Supervised Learning? first. Table of contents Classification vs regression at a glance What is classification? What is regression? Common algorithms for each task Evaluation metrics for each task How to choose the right task A side-by-side Python example Common mistakes Frequently asked questions Conclusion Classification vs regression at a glance The table below summarizes the main differences. The rows give you a quick reference, and the sections after it explain each point. Aspect Classification Regression Goal Assign an example to a class Predict a numeric quantity Output type Discrete labels (for example “cat,” “dog”) Continuous numbers (for example 245.7) Typical question “Which one?” or “Yes or no?” “How much?” or “How many?” Example Will this customer cancel? (yes/no) How much will this customer spend? Common algorithms Logistic regression, decision tree classifier, k-nearest neighbors Linear regression, decision tree regressor, random forest regressor Common metrics Accuracy, precision, recall, F1-score, ROC-AUC MAE, MSE, RMSE, R-squared Typical diagnostic Confusion matrix Predicted-versus-actual plot, residual plot One rule sits behind every row: the target variable decides the task, not the algorithm. If the target is a category, you have a classification problem. If the target is a measurable number, you have a regression problem. What is classification? Classification models learn to place each example into one of several predefined classes. The model looks at the features, such as the words in an email, and outputs a class label. Binary classification Binary classification has exactly two classes. Examples include spam versus not spam, fraud versus legitimate, and disease present versus absent. By convention, programmers often call one class “positive” and the other “negative.” The positive class is usually the one you care most about finding. Multiclass classification Multiclass classification has three or more classes, and each example belongs to exactly one. Recognizing handwritten digits from 0 to 9 and sorting news stories into sports, politics, or business are typical cases. Multilabel classification In multilabel classification, one example can have several labels at once. A photo might be tagged “beach,” “sunset,” and “people” together. Many beginners overlook this type, but it appears often in tagging systems. Many classifiers can output probabilities, for example “82% likely to be spam,” and then convert the probability into a class using a threshold. This detail causes a lot of confusion, because a probability is a number. The model is still a classifier, since its final job is to choose a class. What is regression? Regression models predict a numeric value. The target can take any value in a range, and nearby values mean similar things: a price of 200,000 is close to 201,000. The model outputs one number for each example. Typical regression tasks include predicting house prices, estimating how many minutes a delivery will take, forecasting energy use, and predicting a patient’s blood pressure from other measurements. A regression model rarely hits the exact true value, so we judge it by how far off its predictions are on average. The simplest version, simple linear regression, fits a straight line through the data. You can study it in detail in Linear Regression Explained with Examples. Common algorithms for each task Many algorithms come in two versions: one for classification and one for regression. The core idea stays the same, but the final output and the loss function differ. Algorithm family Classification version Regression version Linear models Logistic regression Linear regression, ridge, lasso Decision trees DecisionTreeClassifier DecisionTreeRegressor Random forests RandomForestClassifier RandomForestRegressor Nearest neighbors KNeighborsClassifier KNeighborsRegressor Support vector machines SVC SVR Logistic regression deserves a special note. Despite its name, it is a classification algorithm. It uses a regression-style equation internally, then converts the result into a probability and a class. The article on logistic regression explains how this works. Decision trees show the “two versions” idea clearly. A classification tree ends each branch with a class label. A regression tree ends each branch with an average of the numbers that landed there. You can explore the method in Decision Trees in Machine Learning: How They Work. Evaluation metrics for each task You cannot use the same score for both tasks. Accuracy means nothing when the target is a price, and average error means nothing when the target is a class. Classification metrics Accuracy: the share of predictions that are correct. Precision: among examples predicted positive, the share that really are positive. Recall: among truly positive examples, the share the model found. F1-score: a single number that balances precision and recall. ROC-AUC: how well the model ranks positives above negatives across all thresholds. Regression metrics MAE (mean absolute error): the average size of the errors, in the units of the target. MSE (mean squared error): the average of squared errors, which punishes large mistakes more. RMSE (root mean squared error): the square root of MSE, back in the units of the target. R-squared: the share of the target’s variation that the model explains. Each metric has traps. For example, accuracy can look excellent on a dataset where 95% of examples belong to one class. The full discussion lives in How to Evaluate a Supervised Learning Model. How to choose the right task Use these questions to decide. Work through them in order. Step 1: Look at the target Ask what the answer looks like. If it is a label from a list, choose classification. If it is a quantity that can take many values, choose regression. Step 2: Think about what the decision needs Sometimes the same business question can be framed both ways. A store might want

Scroll to Top