Learn AI / 3. Machine learning / 3.2
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
| Algorithm | How it works, in one breath | Good for |
|---|---|---|
| Linear regression | Fits a straight line (or flat plane) through the data that minimizes squared error | Simple numeric prediction; a baseline |
| Logistic regression | Like linear regression, but squashes the output into a probability between 0 and 1 | Yes/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 vote | Small datasets; intuitive baselines |
| Decision tree | Learns a flowchart of yes/no questions ("income > $50k?") that splits data into purer groups | Interpretable rules; mixed data types |
| Random forest | Trains many decision trees on random subsets of data and features, then averages their votes | Strong, robust default |
| Gradient-boosted trees (XGBoost, LightGBM) | Builds trees one after another, each correcting the previous ones' mistakes | Usually the best performer on spreadsheet-style data |
| Support vector machine (SVM) | Finds the boundary between classes with the widest possible margin | Medium-sized datasets with clear separation |
| Neural network | Many layers of simple units learning features automatically | Images, 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.