Skip to content
Lambdian

How to choose a machine learning algorithm: a practical guide

A step-by-step way to pick the right machine learning algorithm for your data: start from the task, the size and type of data, and what you need to explain, with sensible defaults for each case.

Lambdian Learn 10 min read

There is no single best algorithm; which one wins depends on the data. But you do not need to try all fifty either. A few questions about your task and data narrow the field to two or three sensible candidates, and a simple baseline tells you whether anything fancier is worth it.

Step 1: name the task

  • Predict a number (price, time, demand): regression.
  • Predict a category (spam, churn, diagnosis): classification.
  • Group similar items with no labels: clustering.
  • Spot unusual items: anomaly detection.
  • Compress or visualise many features: dimensionality reduction.
  • Make a sequence of decisions to maximise a long-term score: reinforcement learning.

If you are not sure which family you are in, read supervised vs unsupervised vs reinforcement learning first.

Step 2: always start with a baseline

Before any real model, compute the score of a trivial one: predict the mean for regression, the most common class for classification. Then fit the simplest real model: linear regression or logistic regression with standardised features.

This takes minutes and answers two important questions. Is there signal at all? And how much does a complex model actually add? Surprisingly often, a well-regularised linear model is within a point or two of the best, and it is far easier to explain and maintain.

Step 3: let the data type decide

  • Tabular data (rows and columns, as in a spreadsheet or database): gradient-boosted trees (XGBoost, LightGBM, CatBoost) are the strongest general choice; random forests are a robust, low-tuning alternative. Trees handle mixed feature types and do not need scaling.
  • Images: convolutional neural networks, usually starting from a pre-trained model.
  • Text: start with a linear model on TF-IDF features (fast, strong baseline), then pre-trained transformer models if you need more.
  • Sequences and time series: lag features plus gradient boosting is a strong baseline; recurrent networks or transformers when sequences are long and data plentiful.
  • Graphs and relations: spectral methods, matrix factorisation for user–item data, or graph neural networks.

Step 4: let the data size decide

  • Hundreds of rows: prefer simple, strongly regularised models (ridge, logistic regression, small trees, naive Bayes, k-NN). Use cross-validation; a single split is too noisy.
  • Thousands to millions of rows: tree ensembles shine; kernel SVMs become slow beyond tens of thousands of rows.
  • Very many features, few rows (genes, text): linear models with L1 or L2 penalties, or naive Bayes.
  • Huge data: models trained with stochastic gradient descent (linear models, neural networks) scale best.

Step 5: what do you need to explain?

If a decision must be justified (credit, medicine, hiring), favour models whose reasoning can be read: linear and logistic regression (coefficients), small decision trees (rules), naive Bayes. Ensembles and neural networks can be explained after the fact with feature importance or SHAP values, but those are approximations of the model's behaviour.

Also consider speed: k-NN is instant to train but slow to predict; boosting is slower to train but fast at prediction; neural networks need GPUs to train at scale.

Quick defaults

  • Tabular regression or classification: logistic or linear regression baseline, then gradient boosting.
  • Small dataset, need explanation: regularised logistic regression or a shallow decision tree.
  • Clustering: k-means if clusters are round and you know roughly how many; DBSCAN if shapes are irregular or there is noise; Gaussian mixtures if you want soft probabilities.
  • Anomalies: isolation forest.
  • Visualising high-dimensional data: PCA first, then t-SNE.
  • Sequential decisions with a simulator: Q-learning for small problems, PPO for large ones.

Whatever you choose, compare candidates with the same cross-validation folds and the metric that matches the real cost of mistakes, then check the winner once on a held-out test set.

Learn these hands-on