Supervised Learning Algorithms: A Practical Guide
Supervised learning algorithms learn from labelled examples and then predict labels or values for new data. Beyond linear and logistic regression, the four you will meet most often are decision trees, k-nearest neighbours (KNN), support vector machines (SVM) and ensembles such as random forests and gradient boosting. This guide explains how each one works, when to use it, and how the bias–variance trade-off ties them together.
Classification vs regression
Supervised problems come in two flavours. Classification predicts a category, such as spam or not spam, a handwritten digit, or a loan decision. Regression predicts a continuous number, such as a price or a temperature. Most algorithms below can do both.
When there are more than two classes, binary classifiers are extended with two strategies: one-vs-all trains one classifier per class, while one-vs-one trains a classifier for every pair of classes and lets them vote.
Decision trees
A decision tree asks a sequence of yes/no questions about the features, such as “Is age above 50?” or “Is cholesterol high?”, until it reaches a leaf that assigns a class. Each split is chosen to make the resulting groups as pure as possible, measured with entropy / information gain or Gini impurity.
- Strengths: easy to explain, handle mixed feature types, need little preprocessing.
- Weaknesses: a deep tree memorises noise. Limit depth, set a minimum number of samples per leaf, or prune the tree.
Regression trees work the same way but predict a number: each leaf outputs the average target of the training samples that land in it, and splits are chosen to minimise the squared error.
K-nearest neighbours (KNN)
KNN does not really “train”. To classify a new point, it finds the k closest labelled points and takes a majority vote (or the average, for regression).
- A small k follows the data closely and overfits noise; a large k smooths too much and underfits. Pick k with cross-validation.
- Because KNN relies on distance, scale your features first, or a feature measured in thousands will drown out one measured in decimals.
- Prediction gets slow on very large datasets, since every new point is compared with stored examples.
Support vector machines (SVM)
An SVM looks for the boundary that separates the classes with the widest possible margin. The points closest to the boundary, the support vectors, define it. When the classes cannot be separated by a straight line, the kernel trick (for example the RBF kernel) lets the SVM draw curved boundaries without computing new features explicitly.
- The
Cparameter trades a wide margin against misclassified training points. - SVMs work well on medium-sized, high-dimensional data such as text, and are used for tasks like anomaly detection and image classification. They scale poorly to millions of rows.

Bias, variance and ensembles
Every model makes two kinds of error. Bias is being consistently off target because the model is too simple. Variance is being inconsistent because the model reacts too strongly to the particular training sample. As complexity grows, bias falls and variance rises; the goal is the point where their total is lowest.

Ensembles combine many models to beat this trade-off:
- Bagging trains many deep trees on random bootstrap samples and averages them. Averaging cuts variance. A random forest also picks a random subset of features at each split.
- Boosting trains shallow trees one after another, each focusing on the errors of the previous ones. This cuts bias. Popular implementations include gradient boosting, XGBoost, LightGBM and AdaBoost.
Which supervised learning algorithms should you try first?
| Situation | Good first choice |
|---|---|
| You must explain every decision | Logistic regression or a shallow decision tree |
| Small dataset, smooth boundaries | KNN or SVM (scale features first) |
| Tabular data, best accuracy | Random forest or gradient boosting |
| High-dimensional sparse data such as text | Linear SVM or logistic regression |
Comparing models in scikit-learn
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
models = {
"tree": DecisionTreeClassifier(max_depth=4),
"knn": make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=15)),
"svm": make_pipeline(StandardScaler(), SVC(kernel="rbf")),
"forest": RandomForestClassifier(n_estimators=300),
}
for name, model in models.items():
scores = cross_val_score(model, X, y, cv=5)
print(f"{name}: {scores.mean():.3f}")
The scikit-learn supervised learning guide documents every algorithm above in detail. Cross-validation gives a fairer comparison than a single train/test split. We cover it in depth in How to Evaluate Machine Learning Models.
A simple workflow for choosing supervised learning algorithms
- Define the target. A category means classification; a number means regression.
- Start with a baseline. Logistic or linear regression gives you a score that every other model must beat.
- Try two or three different families, for example a random forest, a gradient-boosted model and an SVM or KNN with scaled features.
- Compare with cross-validation, using the metric that matches your goal rather than accuracy by default.
- Tune the best one or two with grid or randomised search, then test once on held-out data.
- Weigh accuracy against cost. A slightly less accurate model that is faster, cheaper or easier to explain is often the better choice in production.
This loop keeps your comparison of supervised learning algorithms fair and stops you from chasing tiny gains on a single lucky split. For the full learning path, see our complete guide to machine learning with Python.
Build these models step by step
Module 3 of IBM’s Machine Learning with Python walks through classification, trees, KNN, SVM and ensembles with labs. Read our review or view the course on Coursera.
FAQ
What is the difference between a decision tree and a random forest?
A random forest is many decision trees trained on different random samples and features, with their predictions averaged. It is usually far more accurate and stable than a single tree, but harder to explain.
Why does KNN need feature scaling?
KNN compares distances. Without scaling, features with large numeric ranges dominate the distance and the others are effectively ignored.
Is SVM still worth learning?
Yes. Boosted trees often win on large tabular datasets, but SVMs remain strong on smaller, high-dimensional problems and teach important ideas such as margins and kernels.