Classic ML Algorithms at a Glance

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Before deep networks became the default for images, text and audio, a small set of algorithm families covered most of applied machine learning, and on many problems they still do: tabular data, small datasets, tight latency or interpretability requirements. This page is a map of those families. For each one it gives the core idea, what it assumes, where it is strong, where it fails and which scikit-learn page documents it in detail. It is the entry point; the depth lives in the linked pages.

The scikit-learn estimator names refer to scikit-learn 1.9 on Python 3.13, checked on 2026-10-30. Examples were run on Python 3.13 with scikit-learn 1.9 on 2026-11-01. Deep learning is covered from Neural Network Fundamentals onward, and the question of when classic methods beat neural networks on tables is answered in Tabular Data: Gradient Boosting vs Deep Learning.

Why there is no single best algorithm

Every learning algorithm carries an inductive bias: assumptions that let it generalize beyond the training points (the relation is linear, nearby points share labels, features are conditionally independent, the boundary is axis-aligned). An algorithm performs well exactly when its bias matches the problem. The "no free lunch" theorems formalize the consequence: averaged over all possible problems, no algorithm beats any other, so the choice must come from knowledge of the data. In practice that means a short, disciplined routine:

  1. Fit a trivial baseline (DummyClassifier, DummyRegressor) so every score has a reference.

  2. Fit a regularized linear model. If it already meets the requirement, you may be done and you have an interpretable model.

  3. Fit a tree-ensemble (random forest or gradient boosting), which is the strongest general-purpose family on tabular data.

  4. Add other families only if the data suggests it: an RBF-kernel SVM on small dense numeric data, nearest neighbours when a good distance exists, naive Bayes for very high-dimensional sparse text.

  5. Compare all candidates with the same cross-validation folds and a metric that reflects the decision; see Model Evaluation & Validation and the capacity discussion in Generalization, Bias–Variance & Regularization.

flowchart LR ML[Classic ML] --> S[Supervised] ML --> U[Unsupervised] S --> L[Linear and generalized linear] S --> K[Instance based: kNN] S --> P[Probabilistic: naive Bayes] S --> M[Margin based: SVM] S --> T[Trees] T --> E[Ensembles: bagging, boosting, stacking] U --> C[Clustering] U --> D[Dimensionality reduction] U --> O[Density and outlier detection]

The families

Linear and generalized linear models

The prediction is a weighted sum of the features, \(\hat{y} = w^{\top}x + b\), passed for classification through a sigmoid (logistic regression) or softmax. Training minimizes a convex loss, usually with an L2 or L1 penalty (ridge, lasso, elastic net), so the solution is stable and reproducible.

  • Strong: fast to train and predict, scales to millions of rows and very wide sparse data, coefficients are interpretable, calibrated probabilities from logistic regression, a hard baseline to beat.

  • Weak: cannot represent interactions or curvature unless you engineer features (polynomials, splines, crosses); sensitive to feature scale and to outliers; collinear features make coefficients unstable.

  • Needs: scaled features; regularization when features outnumber samples.

  • Page: Linear Models. Regularization theory: Generalization, Bias–Variance & Regularization.

Nearest neighbours

The prediction for a new point is the majority label (or mean target) of its \(k\) closest training points under a distance. There is no training phase beyond storing and indexing the data.

  • Strong: no model assumptions, naturally non-linear, works with any meaningful distance, easy to explain.

  • Weak: prediction cost grows with the training set; distances lose meaning in high dimensions; irrelevant or unscaled features dominate the distance; needs the whole training set at inference.

  • Needs: scaled features, a sensible metric, an index (KD-tree, ball tree) for speed.

  • Page: Nearest Neighbors. The same idea with learned embeddings powers vector search; see Embeddings.

Naive Bayes

Applies Bayes' rule with the "naive" assumption that features are independent given the class, so the class-conditional density factorizes: \(p(y\mid x) \propto p(y)\prod_j p(x_j \mid y)\). The Gaussian, multinomial, Bernoulli and complement variants differ in the per-feature distribution.

  • Strong: trains in one pass, needs little data, handles very high-dimensional sparse features such as word counts, strong baseline for text.

  • Weak: the independence assumption is almost always false, so the predicted probabilities are poorly calibrated (the ranking is often fine); it cannot learn feature interactions.

  • Page: Naive Bayes; calibrate the output with Probability Calibration when probabilities matter.

Support vector machines

A support vector machine finds the decision boundary with the largest margin between classes and depends only on the training points closest to it (the support vectors). The kernel trick (RBF, polynomial) lets it learn non-linear boundaries by implicitly working in a high-dimensional feature space; \(C\) trades margin width against training errors.

  • Strong: excellent on small to medium dense datasets, effective when features outnumber samples, flexible through kernels.

  • Weak: kernel SVM training time grows between quadratically and cubically with the number of samples, so it is impractical beyond a few hundred thousand rows; needs scaled features and tuning of \(C\) and the kernel parameters; no native probabilities (they are obtained by an expensive internal cross-validation).

  • Page: Support Vector Machines.

Decision trees

A tree recursively splits the feature space with axis-aligned thresholds chosen to maximize the reduction of an impurity measure (Gini or entropy for classification, squared error for regression). The prediction is the majority class or mean value of the leaf.

  • Strong: no feature scaling, handles mixed numeric and categorical data once encoded, captures interactions, human-readable for shallow trees.

  • Weak: a single deep tree overfits badly (high variance), is unstable to small data changes, produces piecewise-constant predictions (no extrapolation beyond the training range) and has staircase boundaries for oblique relations.

  • Control with max_depth, min_samples_leaf, and cost-complexity pruning.

  • Page: Decision Trees.

Tree ensembles

Combining many trees removes most of a single tree’s weakness.

  • Random forests and bagging average trees fitted on bootstrap samples with random feature subsets. They reduce variance, need little tuning, give out-of-bag error estimates and parallelize. Page: Random Forests & Bagging.

  • Gradient boosting adds shallow trees one at a time, each fitted to the errors of the ensemble so far. It reduces bias and is usually the most accurate classic method on tabular data, at the price of more hyperparameters. Page: Histogram Gradient Boosting; libraries and the comparison with deep learning in Tabular Data: Gradient Boosting vs Deep Learning.

  • Voting and stacking combine heterogeneous models, either by averaging or by training a meta-model on out-of-fold predictions. Page: Voting, Stacking & Multiclass.

Clustering and mixtures

Unsupervised grouping of unlabelled data: k-means (compact spherical clusters, requires the number of clusters), hierarchical clustering (a dendrogram of merges), DBSCAN and HDBSCAN (density-based, arbitrary shapes, a noise label), and Gaussian mixtures (soft assignments, elliptical clusters, probabilistic model). Results depend strongly on scaling and on the metric, and there is no ground truth to validate against, so internal indices (silhouette) and domain checks are essential.

Dimensionality reduction and manifold learning

PCA projects onto the orthogonal directions of greatest variance and is linear, fast and invertible. Non-linear methods (t-SNE, UMAP-style embeddings, Isomap) preserve neighbourhoods and are mostly for visualization; their distances and cluster sizes should not be over-interpreted. Feature selection (filters, wrappers, embedded L1 selection) removes columns instead of mixing them. The mathematics behind PCA (eigendecomposition, SVD) is in Math for ML: Linear Algebra, Calculus & Probability.

Outlier and novelty detection

Isolation forests, local outlier factor, one-class SVMs and robust covariance estimators flag unusual rows without labels. Distinguish outlier detection (the training data contains anomalies) from novelty detection (the training data is clean and new data is tested). Page: Outlier & Novelty Detection.

Side-by-side summary

Family Feature scaling Handles interactions Training cost Typical sweet spot

Linear and logistic regression

Required

No, unless engineered

Low

Wide or sparse data, interpretability, baseline

k-nearest neighbours

Required

Implicitly

None (cost moves to prediction)

Small data with a good metric

Naive Bayes

Not needed (Gaussian: helpful)

No

Very low

High-dimensional text counts

Kernel SVM

Required

Through the kernel

High (superlinear in samples)

Small or medium dense numeric data

Single decision tree

Not needed

Yes

Low

Explainable rules, quick checks

Random forest

Not needed

Yes

Medium, parallel

Robust default with little tuning

Gradient boosting

Not needed

Yes

Medium to high

Best accuracy on tabular data

MLP (neural network)

Required

Yes

High

Large data, non-tabular signals

These are tendencies, not laws. The sizes at which each method becomes impractical depend on hardware and implementation; the decision guide in Choosing an Estimator discusses the official estimator map and its size thresholds with appropriate caution.

A cross-validated comparison

The example evaluates the families on the same data with identical stratified folds and ROC AUC. Methods that need scaling get a StandardScaler inside the pipeline so the scaler is refitted on the training part of every fold.

from sklearn.datasets import load_breast_cancer
from sklearn.dummy import DummyClassifier
from sklearn.ensemble import HistGradientBoostingClassifier, RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier

X, y = load_breast_cancer(return_X_y=True)
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)


def scaled(est):
    return make_pipeline(StandardScaler(), est)


candidates = {
    "baseline (most frequent)": DummyClassifier(strategy="most_frequent"),
    "logistic regression": scaled(LogisticRegression(max_iter=1000)),
    "k-nearest neighbours": scaled(KNeighborsClassifier()),
    "naive Bayes": GaussianNB(),
    "SVM (RBF kernel)": scaled(SVC()),
    "decision tree": DecisionTreeClassifier(max_depth=4, random_state=0),
    "random forest": RandomForestClassifier(n_estimators=300, random_state=0),
    "hist gradient boosting": HistGradientBoostingClassifier(random_state=0),
    "MLP": scaled(MLPClassifier(hidden_layer_sizes=(64,), max_iter=1000, random_state=0)),
}
for name, est in candidates.items():
    scores = cross_val_score(est, X, y, cv=cv, scoring="roc_auc")
    print(f"{name:26s} ROC AUC {scores.mean():.3f} +/- {scores.std():.3f}")

Output:

baseline (most frequent)   ROC AUC 0.500 +/- 0.000
logistic regression        ROC AUC 0.995 +/- 0.006
k-nearest neighbours       ROC AUC 0.981 +/- 0.009
naive Bayes                ROC AUC 0.989 +/- 0.006
SVM (RBF kernel)           ROC AUC 0.996 +/- 0.005
decision tree              ROC AUC 0.921 +/- 0.025
random forest              ROC AUC 0.992 +/- 0.007
hist gradient boosting     ROC AUC 0.994 +/- 0.005
MLP                        ROC AUC 0.993 +/- 0.005

On this small, clean, roughly linearly separable dataset the differences among the top six are within one standard deviation of each other, so they are not distinguishable, while the single shallow tree is clearly behind. That is the typical lesson: on easy data many families tie, and the simpler one (logistic regression) wins on cost and explainability. Do not read a ranking from one dataset. Source: scikit-learn user guide: Cross-validation.

Choosing by data characteristics

Situation Reasonable first choices

Few hundred rows, numeric features

Regularized logistic or ridge regression, SVM with RBF kernel, kNN

Millions of rows, sparse high-dimensional features (text, one-hot)

Linear models with SGD solvers, naive Bayes

Mixed numeric and categorical columns, missing values

Gradient boosting, random forest

Need to explain a decision

Linear model with coefficients, shallow tree, monotonic-constrained boosting

Need calibrated probabilities

Logistic regression, or any model followed by calibration

Unlabelled data, want groups

k-means or Gaussian mixture after scaling, HDBSCAN for irregular shapes

Many correlated features, want compact representation

PCA, then a simple model

Images, audio, raw text, graphs

Neural networks; see Convolutional Neural Networks and Attention & Transformers

Pitfalls

  • Comparing algorithms with default hyperparameters on one split. Tune each candidate fairly (inside nested cross-validation if the comparison is the result) and use the same folds.

  • Forgetting to scale for distance- and gradient-based methods (kNN, SVM, linear models with penalties, MLP) while tree methods are indifferent.

  • Treating class probabilities from naive Bayes, SVM or boosted trees as calibrated.

  • Using a deep tree or k=1 neighbour on noisy data and concluding "the algorithm is bad".

  • Choosing an algorithm for its sophistication. A baseline and a regularized linear model are quick to build and reveal how much signal exists.

  • Old books and tutorials import modules that no longer exist (sklearn.cross_validation, sklearn.grid_search, sklearn.lda) or use removed arguments; follow the current user guide instead.