Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.

Get Started Now!

How Does Machine Learning Work: Your Ultimate Guide For 2020

How Does Machine Learning Work: Your Ultimate Guide For 2020
Machine Learning

Last updated: 05 December 2026

So, how does machine learning work? In short, a machine learning system finds patterns in example data and uses them to make predictions about new data. Nobody writes the rules by hand. The program adjusts its own internal numbers until its predictions match the examples as closely as possible.

The title of this guide once referred to 2020. The core ideas have not changed since then: data, a model, a loss function, an optimisation step and honest evaluation. What has changed is the tooling and the scale. This guide explains the fundamentals, so it stays useful whichever tools are fashionable.

Machine learning in one paragraph

Traditional software takes rules and data and produces answers. Machine learning flips this: it takes data and answers (labelled examples) and produces the rules, which we call a model. The model is then applied to new data to produce answers of its own.

Take a hypothetical spam filter. Instead of writing “if the email contains ‘prize’, mark it as spam”, you show the system thousands of emails already labelled spam or not spam. It learns which word patterns tend to go with each label.

The core ingredients

  • Data: the examples the system learns from. Quality and relevance matter more than raw volume.
  • Features: the measurable inputs, such as word counts, pixel values or a customer’s age. In deep learning, the model often learns its own features from raw input.
  • Labels: the correct answers, when you have them.
  • Model: a mathematical function with adjustable numbers called parameters (or weights).
  • Loss function: a score that measures how wrong the model’s predictions are.
  • Optimiser: the procedure that changes the parameters to reduce the loss. Gradient descent is the classic example.

How machine learning works, step by step

Flow diagram: data is prepared, a model is trained, evaluated, deployed and monitored, with monitoring feeding back into new data
The machine learning loop, from raw data to a monitored model

1. Collect and prepare data

You gather examples and clean them: remove duplicates, handle missing values, fix inconsistent formats and encode text or categories as numbers. This step often takes most of a project’s time.

You then split the data into at least two parts. A training set is used to learn. A test set is held back and used only at the end to estimate real-world performance. Many teams also keep a validation set for comparing settings along the way.

2. Choose a model

The model type depends on the problem and the data. Linear and logistic regression, decision trees and random forests suit tabular data well. Neural networks suit images, audio and language, where patterns are complex.

3. Train the model

Training is a loop:

  1. The model makes predictions on training examples.
  2. The loss function scores how far those predictions are from the labels.
  3. The optimiser nudges the parameters in the direction that reduces the loss.
  4. Repeat many times until the loss stops improving.

In a neural network, step 3 uses backpropagation to work out how much each weight contributed to the error. Gradient descent then updates every weight by a small amount.

4. Evaluate on unseen data

A model that scores well on its training data may simply have memorised it. You measure it on the held-out test set with a metric that fits the task: accuracy, precision and recall, F1 score, or mean absolute error for numeric predictions. If results are poor, you go back, change features, model or settings, and retrain.

5. Deploy and monitor

A useful model is put behind an application or an API. Real-world data shifts over time, such as new customer behaviour or new slang. This is called drift, and it can quietly degrade performance. So you monitor results and retrain when needed.

The main types of machine learning

Type Learns from Typical tasks Example
Supervised Labelled examples Classification, regression Predicting house prices from past sales
Unsupervised Unlabelled data Clustering, dimensionality reduction Grouping customers by behaviour
Self-supervised Labels derived from the data itself Pretraining language and vision models Predicting the next word in a text
Reinforcement Rewards from trial and error Control, games, sequential decisions An agent learning to play a game

A tiny worked example

Imagine fitting a straight line to predict a price from floor area: price = w × area + b. The numbers w and b start as guesses. For each house, the model predicts a price, and the loss (for example, the average squared error) measures the gap to the real price. The optimiser shifts w and b slightly to shrink that gap. After enough rounds, the line fits the data well. Every larger model, including neural networks with billions of parameters, follows this same principle at greater scale.

Hands-on exercise: train a classifier

This short Python script trains a model on a small built-in dataset. It uses scikit-learn. The code has not been tested here, so check it in your own environment.

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)

model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)          # training

pred = model.predict(X_test)         # predicting on unseen data
print("Accuracy:", accuracy_score(y_test, pred))

Try these extensions:

  • Swap in LogisticRegression and compare the accuracy.
  • Change test_size and see how the score varies.
  • Print model.feature_importances_ to see which inputs mattered most.

Common problems and how to fix them

Overfitting

The model performs well on training data but poorly on new data. Remedies include more data, a simpler model, regularisation, early stopping and cross-validation.

Underfitting

The model is too simple to capture the pattern, so it does badly everywhere. Use a more expressive model, better features or longer training.

Data leakage

Information from the test set sneaks into training, for example by scaling the whole dataset before splitting. Scores look excellent and then collapse in production. Always split first, then fit any preprocessing on the training data only.

Biased or unrepresentative data

A model reflects its data. If some groups are under-represented or labels encode past prejudice, predictions will too. Examine your data, evaluate results per group, and document known limits.

Imbalanced classes

If 99% of examples belong to one class, a model that always predicts it gets 99% accuracy and is useless. Use precision, recall or F1, and consider resampling or class weights.

Best practices

  • Start with a simple baseline. If a complex model barely beats it, the complexity is not paying off.
  • Define the success metric before you train anything.
  • Keep the test set untouched until the final check.
  • Set random seeds and record versions of data and code so results can be reproduced.
  • Plan for monitoring and retraining from the start.
  • Ask whether machine learning is needed at all. A simple rule is sometimes better.

Where deep learning and generative AI fit

Deep learning is a subset of machine learning that uses neural networks with many layers. Modern generative AI systems, including large language models, are built on the same training loop described above. They are trained on very large datasets to predict the next piece of text or another output. The difference is mainly scale and architecture, not a different kind of learning.

FAQ

Is machine learning the same as artificial intelligence?

No. Artificial intelligence is the broader goal of building systems that perform tasks needing intelligence. Machine learning is one approach to it, in which systems learn from data.

Do I need advanced maths to understand it?

Not to grasp the ideas or to use libraries. To go deeper, basic linear algebra, probability and calculus help a lot, especially for understanding gradient descent.

How much data do I need?

There is no universal number. Simple models can work with hundreds of examples, while large neural networks need far more. Learning curves, which plot performance against training set size, show whether more data would help.

Does the model really “understand” anything?

It learns statistical patterns that map inputs to outputs. It can be very capable, but it can also fail in surprising ways on data unlike what it was trained on.

Which language should I learn?

Python is the most common choice, with libraries such as scikit-learn, PyTorch and TensorFlow.

Key takeaways

Machine learning works by showing a model many examples, measuring its errors with a loss function and adjusting its parameters to reduce them. The real test is performance on data it has never seen. Good data, a fair evaluation and ongoing monitoring matter more than picking the most advanced algorithm.

Related reading

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x