What is a machine learning algorithm?
A machine learning algorithm is a procedure that learns patterns from data. You give it examples, it adjusts internal numbers to fit those examples, and the result can then make predictions on new data. Linear regression, decision trees, k-means and neural networks are all ML algorithms.
There are dozens of ML algorithms, but they fall into a few families. The family depends on the task: predicting a number (regression), predicting a category (classification), finding groups without labels (clustering), simplifying many columns into a few (dimensionality reduction), or learning complex patterns in images, audio and text (neural networks). Learn the families first and the long list of names becomes much easier to remember.
ML model vs algorithm: what is the difference?
People often use the two words as if they mean the same thing, but they do not. The algorithm is the recipe. The model is what you get after running that recipe on your data.
For example, 'random forest' is an algorithm. When you call fit() on your customer data, it builds a specific set of trees with specific splits, and that trained object is your ML model. Two teams using the same algorithm on different data end up with different models. When people talk about machine learning models in production, they mean these trained objects, saved to a file and loaded by an app to make predictions.
| Algorithm | Model | |
|---|---|---|
| What it is | A general method for learning from data | The trained result of that method on one dataset |
| Example | Logistic regression | A churn classifier with learned weights for 20 customer features |
| When it exists | Before you have any data | Only after training |
| What you ship | Nothing on its own | The saved model file, used to make predictions |
Machine learning algorithms list: the master table
This table covers the machine learning algorithms you will meet most often, from simple baselines to the ones that win competitions. Use it as a quick reference before you go deeper into each one.
| Algorithm | Type | Typical use case | Strengths | Weaknesses |
|---|---|---|---|---|
| Linear regression | Supervised, regression | Predicting price, sales or demand | Fast, easy to explain, a strong baseline | Assumes a straight-line relationship; sensitive to outliers |
| Ridge, Lasso, Elastic Net | Supervised, regression | Regression with many or correlated features | Reduces overfitting; Lasso can drop useless features | Still linear; needs scaled features and a tuned penalty |
| Logistic regression | Supervised, classification | Churn, default risk, spam detection | Gives probabilities, quick, explainable coefficients | Misses complex non-linear patterns unless you engineer features |
| K-nearest neighbors (KNN) | Supervised, classification or regression | Simple recommendations, small datasets | No training step, easy to understand | Slow on large data; hurt by irrelevant or unscaled features |
| Naive Bayes | Supervised, classification | Text classification, spam filters | Very fast, works with little data and many words | Assumes features are independent, so probabilities can be off |
| Support vector machine (SVM) | Supervised, classification or regression | Medium-sized data with clear margins, text | Handles high dimensions; kernels capture curves | Slow on very large datasets; needs scaling and tuning |
| Decision tree | Supervised, classification or regression | Rules a business can read, quick baselines | Easy to visualise, handles mixed feature types | Overfits easily; small data changes alter the tree |
| Random forest | Supervised, ensemble (bagging) | General tabular problems, feature importance | Accurate with little tuning, resists overfitting | Larger and slower than one tree; harder to explain |
| Gradient boosting (XGBoost, LightGBM, CatBoost) | Supervised, ensemble (boosting) | Churn, fraud, ranking, most tabular data | Often the most accurate choice on tables | More hyperparameters; can overfit if not tuned |
| K-means | Unsupervised, clustering | Customer segmentation | Simple and fast | You must pick K; assumes round, similar-sized clusters |
| DBSCAN | Unsupervised, clustering | Location data, clusters of odd shapes, noise | Finds any shape; marks outliers as noise | Struggles when clusters have very different densities |
| Hierarchical clustering | Unsupervised, clustering | Small datasets where a tree of groups helps | No need to fix K in advance; dendrogram view | Slow on large data |
| PCA | Unsupervised, dimensionality reduction | Compressing features, visualisation | Removes redundancy, speeds up later models | New components are hard to interpret; only linear |
| Isolation Forest | Unsupervised, anomaly detection | Fraud and fault detection | Works well on many features, fast | Needs a guess of how rare anomalies are |
| Neural networks (MLP, CNN, RNN, Transformer) | Supervised or self-supervised, deep learning | Images, speech, text, very large datasets | Learns complex patterns and its own features | Needs lots of data and compute; hard to explain |
Supervised learning algorithms: regression and classification
Supervised learning algorithms learn from rows where the answer is already known. They are the most used type of machine learning algorithms because most business data comes with historical outcomes.
Regression algorithms predict a continuous number. Linear regression fits a straight line (or flat plane) through the data and is the first thing to try. Polynomial regression bends that line by adding squared or interaction terms. Ridge, Lasso and Elastic Net add a penalty on large weights to stop the model memorising noise. Phase 7 of this roadmap covers all of these, along with regression metrics like MAE, RMSE and R squared.
Machine learning classification algorithms predict a category. Logistic regression is the standard baseline and outputs a probability between 0 and 1. K-nearest neighbors labels a new point by looking at the closest training points. Naive Bayes applies Bayes' theorem and is a classic for spam and text. Support vector machines find the boundary with the widest gap between classes, and kernels let them draw curved boundaries. Phase 8 covers these classifiers and the metrics that judge them, such as precision, recall, F1 and ROC-AUC.
Ensembles, unsupervised algorithms and neural networks
Ensemble methods combine many models into one stronger model. Bagging trains many decision trees on random samples of the data and averages them, which is how a random forest works. Boosting trains trees one after another, each fixing the mistakes of the previous ones, which is the idea behind gradient boosting, XGBoost, LightGBM and CatBoost. On structured, spreadsheet-style data, gradient boosting is very often the strongest choice. Phase 9 covers decision trees, random forests, boosting, stacking and feature importance.
Unsupervised algorithms work without labels. K-means, hierarchical clustering, DBSCAN and Gaussian mixture models find groups. PCA, t-SNE and UMAP reduce many columns to a few. Isolation Forest finds anomalies, and Apriori finds items that are often bought together. Phase 11 walks through each of these, ending with a customer segmentation project.
Neural networks are layers of simple units that each compute a weighted sum and pass it through an activation function. Stack many layers and you get deep learning. Convolutional neural networks (CNNs) suit images, and transformers now lead in text and many other areas. Most of the AI algorithms in the news today, from chatbots to image generators, are large neural networks. Phase 12 teaches how they learn with backpropagation in PyTorch, and Phase 13 applies them to computer vision and NLP.
How to choose a machine learning algorithm
There is no single best algorithm for every problem. Instead, follow a short checklist and let your validation scores decide.
- Define the task. A number target means regression, a category means classification, and no target means clustering or another unsupervised method.
- Look at the data type. Tables of rows and columns usually suit linear models and tree ensembles. Images, audio and free text usually suit neural networks.
- Check the data size. With a few hundred rows, simple models and strong regularisation are safer. Deep learning normally needs far more examples.
- Decide how much explanation you need. If a bank must justify every rejection, logistic regression or a shallow tree may beat a slightly more accurate black box.
- Start with a baseline, then try a stronger family. Logistic or linear regression first, then random forest and gradient boosting, all compared with the same cross-validation.
- Tune only the best one or two. Hyperparameter search on every algorithm wastes time. Phase 10 covers cross-validation, tuning with grid search and Optuna, and choosing between models fairly.
Compare 3 classifiers in scikit-learn
This snippet compares logistic regression, a decision tree and a random forest on scikit-learn's built-in breast cancer dataset using 5-fold cross-validation. The logistic regression sits inside a pipeline with a scaler, because it trains better on standardised features. Run it in Google Colab and see which one wins on your machine.
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
X, y = load_breast_cancer(return_X_y=True)
models = {
"Logistic regression": make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)),
"Decision tree": DecisionTreeClassifier(max_depth=4, random_state=42),
"Random forest": RandomForestClassifier(n_estimators=300, random_state=42),
}
for name, model in models.items():
scores = cross_val_score(model, X, y, cv=5, scoring="accuracy")
print(f"{name}: {scores.mean():.3f} (+/- {scores.std():.3f})")