The main supervised learning algorithms

14 min read

Supervised learning comes in two flavors:

  • Regression: predict a number (price, temperature, demand).
  • Classification: predict a category (spam / not spam; which digit is in an image).

The classic algorithms

AlgorithmHow it works, in one breathGood for
Linear regressionFits a straight line (or flat plane) through the data that minimizes squared errorSimple numeric prediction; a baseline
Logistic regressionLike linear regression, but squashes the output into a probability between 0 and 1Yes/no classification; very interpretable
k-nearest neighbors (k-NN)To classify a new point, look at the k most similar training examples and take a voteSmall datasets; intuitive baselines
Decision treeLearns a flowchart of yes/no questions ("income > $50k?") that splits data into purer groupsInterpretable rules; mixed data types
Random forestTrains many decision trees on random subsets of data and features, then averages their votesStrong, robust default
Gradient-boosted trees (XGBoost, LightGBM)Builds trees one after another, each correcting the previous ones' mistakesUsually the best performer on spreadsheet-style data
Support vector machine (SVM)Finds the boundary between classes with the widest possible marginMedium-sized datasets with clear separation
Neural networkMany layers of simple units learning features automaticallyImages, audio, text, very large datasets

Ensembles: the wisdom of crowds

Random forests and boosting are ensembles: many weak models combined into a strong one. Averaging many slightly-wrong models cancels out their individual errors.

Regularization: keeping models humble

Regularization adds a penalty for complexity during training, such as penalizing very large weights (L1 or L2 regularization). This discourages memorizing noise and improves generalization. Other forms include limiting tree depth and stopping training early.

Choosing a first model

  • Tabular data (rows and columns, like a spreadsheet): start with logistic or linear regression as a baseline, then gradient-boosted trees. Deep learning rarely wins here.
  • Images, audio, text: deep learning, usually starting from a pre-trained model.
  • Need to explain every decision (credit, hiring): favor interpretable models like logistic regression or small trees, or pair complex models with explanation tools.

Check your understanding

Check 1 of 2Module 3 · Machine learning

Predicting tomorrow's electricity demand in megawatts is a:

Check 2 of 2Module 3 · Machine learning

For a large spreadsheet of customer data, which model is most often the strongest performer?

Answer the checks, then mark this lesson complete
Completion and scores are saved in this browser.