learn.aathan.in

Supervised Learning: Classification vs Regression

The fundamental split in supervised learning — predicting a number versus predicting a category — with the full algorithm taxonomy, how to tell which problem you have, and the workflow every model follows.

Almost every practical machine learning problem is supervised learning: you have historical examples where you already know the answer, and you want a model that predicts the answer for new cases.

Supervised learning splits into exactly two problem types, and which one you have decides everything else — the algorithms available to you, the loss function, and the metrics you evaluate with.

RegressionClassification
PredictsA number on a continuous scaleA category from a fixed set
Answers”How much / how many?""Which one / is it?”
ExamplesSalary, house price, temperature, demandSpam or not, disease type, will they churn
Output72,300 (any real value)“Yes” / “No” (a label)
Typical metricRMSE, MAE, R²Accuracy, precision, recall, F1
Regression — fit a line output: any number on the line Classification — draw a boundary output: which side of the line
Regression fits a line through the data to predict a value; classification fits a boundary between groups to predict a label.

How to tell which problem you have

Look at your target column (y) and ask: would averaging two of its values mean anything?

  • Salary 50,000 and 70,000 → average 60,000. Meaningful → regression.
  • “Spam” and “Not spam” → no average exists. Meaningless → classification.

Two traps worth knowing:

  1. Numbers that are really categories. A Rating column of 1–5 stars, or PIN codes, or an encoded Country column of 0/1/2 — these look numeric but averaging them is nonsense. That’s classification (or ordinal) data. This is the same trap covered in the statistics variable-types notes.
  2. “Probability of X” is regression-flavoured but still classification. Logistic regression outputs a probability between 0 and 1 — but you ultimately predict a class, so it’s a classification algorithm despite the name.

The full taxonomy

Regression algorithms

AlgorithmBest forNote
Linear RegressionA straight-line relationshipThe baseline — always start here
Multiple Linear RegressionSeveral predictors at onceSame maths, more columns
Polynomial RegressionCurved relationshipsLinear regression on ,
Ridge (L2)Many correlated featuresShrinks coefficients, fights overfitting
Lasso (L1)Feature selection neededCan drive coefficients to exactly zero
ElasticNetBoth of the aboveA blend of L1 and L2
Decision Tree RegressorNon-linear, interpretableProne to overfitting alone
Random Forest RegressorStrong general-purposeMany trees averaged
Gradient Boosting / XGBoostBest tabular accuracyTrees built to fix each other’s errors
SVRSmall, high-dimensional dataSupport vector machines for numbers

Classification algorithms

AlgorithmBest forNote
Logistic RegressionLinearly separable, interpretableThe classification baseline
K-Nearest NeighboursSmall data, irregular boundariesNo training — memorises the data
Naive BayesText, spam filteringFast; assumes features are independent
Decision TreeRules you need to explainHuman-readable
Random ForestStrong general-purposeRobust, little tuning needed
Gradient Boosting / XGBoostBest tabular accuracyUsually wins competitions
SVMClear margins, high dimensionsPowerful with kernels
Neural NetworksImages, audio, textNeeds lots of data

Practical advice: start with the simple baseline (Linear or Logistic Regression). It’s fast, interpretable, and tells you whether the problem is even learnable. Only reach for Random Forest or boosting once you have that number to beat.

The workflow every supervised model follows

Whichever branch you’re on, the pipeline is identical:

1. Get data            ->  pd.read_csv(...)
2. Split X and y       ->  features vs target
3. Clean               ->  handle missing values
4. Encode              ->  text categories -> numbers
5. Split train/test    ->  train_test_split(...)
6. Scale (if needed)   ->  StandardScaler
7. Fit                 ->  model.fit(X_train, y_train)
8. Predict             ->  model.predict(X_test)
9. Evaluate            ->  RMSE / R²   or   accuracy / F1

Steps 1–6 are data preprocessing and are the same for both problem types. Steps 7–8 are identical in scikit-learn — every model exposes the same .fit() / .predict() interface, which is why swapping algorithms is usually a one-line change:

from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor

model = LinearRegression()          # swap this line...
model = RandomForestRegressor()     # ...for this one, nothing else changes
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

Only step 9 genuinely differs between regression and classification — see evaluating models.

Where to go next

  1. Data preprocessing — getting raw data into a shape a model accepts (missing values, encoding, train/test split).
  2. Linear regression — the foundational algorithm, worked end to end by hand and in scikit-learn.
  3. Regression algorithms — everything beyond the straight line.
  4. Classification algorithms — the full set, with how each draws its boundary.
  5. Model evaluation — the metrics for both, and why accuracy alone will mislead you.

Takeaways

  • Supervised learning = learning from labelled examples; it splits into regression (predict a number) and classification (predict a category).
  • The test: would averaging two target values mean anything? Yes → regression.
  • Watch for numeric-looking categories — encoded labels and ratings are not regression targets.
  • The workflow is the same for both; only the algorithm choice and the evaluation metrics differ.
  • Always establish a simple baseline before reaching for complex models.