Maths and Statistics You Need for AI

Generative AI & LLM Fundamentals · AI and machine learning basics · 7 min read · Updated

You can build useful AI products without being a mathematician. But a few ideas show up everywhere, and knowing them makes the rest of AI much less mysterious.

Vectors and matrices

A vector is just a list of numbers, for example [0.2, 0.9, 0.1]. AI turns words, images and documents into vectors so that a computer can compare them. A matrix is a grid of numbers; neural networks are mostly large matrices multiplied together.

Probability and distributions

A language model does not know the next word, it estimates how likely each possible next word is. That is a probability distribution: a list of options with a chance attached to each. Choosing among them is why the same prompt can give different answers.

Mean, variance and standard deviation

The mean is the average. Variance and standard deviation tell you how spread out the values are. You use them to judge whether a result is stable or noisy, for example when you test the same prompt many times.

Derivatives, gradients and gradient descent

Training a model means adjusting millions of numbers (its parameters) so its mistakes get smaller. A loss function measures the mistake. The gradient says which direction to nudge each number to reduce the loss. Gradient descent repeats small nudges until the loss stops improving. Think of walking downhill in fog by always stepping where the ground slopes down.

Similarity measures

To find documents or CVs that are "close in meaning", we compare their vectors.

  • Cosine similarity compares the direction of two vectors. Values near 1 mean very similar meaning.
  • Euclidean distance compares how far apart two points are. Smaller means closer.

Cosine similarity is what powers semantic search and RAG, which you will meet in the RAG course. It is also how a resume and job description matcher can judge how close two texts are.

Frequently asked questions

What maths should I learn first for AI?

Start with vectors, averages and probability. Add gradients and gradient descent when you want to understand how models are trained.

Do I need calculus to use the Claude API?

No. Using an API needs programming skills. The maths helps you understand why models behave the way they do.