Foundations & Concepts
The maths behind AI (made simple)
Learn The maths behind AI (made simple): 34 practice questions and answers with an interactive quiz — from the offline AI Learning app.
Questions & Answers
Tap a question to reveal its answer. Written for self-study and interview preparation.
What is the "mean" (average) of a list of numbers, and why is it useful in AI?
The mean is found by adding all the numbers together and dividing by how many numbers there are. AI often uses the mean to summarise many examples with a single typical value, for example the average error a model makes over thousands of pictures. It gives a quick sense of overall performance instead of looking at every example one by one.
nums = [4, 8, 6, 2]
mean = sum(nums) / len(nums) # 5.0An artificial neuron computes a "weighted sum". If inputs are 2 and 3 with weights 0.5 and 1.0, what is the weighted sum?
A weighted sum multiplies each input by its weight and then adds the results: (2 x 0.5) + (3 x 1.0) = 1 + 3 = 4. Weights tell the neuron how important each input is. Learning means adjusting these weights so the output becomes more accurate.
inputs = [2, 3]
weights = [0.5, 1.0]
total = sum(i*w for i, w in zip(inputs, weights)) # 4.0In the line equation y = mx + c, what does the letter m represent?
The letter m is the slope, which tells you how steep the line is and how much y changes when x increases by 1. The letter c is where the line crosses the y-axis. Many simple AI models fit a line like this to data to make predictions.
What is a vector in the simple maths used by AI?
A vector is just an ordered list of numbers, such as [3, 1, 4]. AI uses vectors to represent things like the features of an image or a word as a row of numbers. Doing maths on vectors lets a computer compare and combine information quickly.
In probability, what range of values can the probability of an event take?
A probability is always between 0 and 1, where 0 means impossible and 1 means certain. A value like 0.5 means a 50 percent chance. AI models often output probabilities to show how confident they are about an answer.
A model labels 100 images and gets 90 correct. What is its accuracy?
Accuracy is the number of correct answers divided by the total number of answers, then often shown as a percentage. Here it is 90 / 100 = 0.9, which is 90 percent. Accuracy is a simple way to measure how well a model is performing.
correct, total = 90, 100
accuracy = correct / total # 0.9 = 90%What does the "error" or "loss" of an AI model measure?
Loss measures how far the model's predictions are from the correct answers, so a smaller loss means a better model. A common method squares each difference and averages them so big mistakes count more. The goal of training is to make the loss as small as possible.
Gradient descent is often compared to walking downhill. What is the model trying to reach?
It is trying to reach the lowest point, which represents the smallest possible error or loss. At each step the model checks the slope and moves a little in the direction that lowers the loss. Repeating this many times slowly improves the model.
What does the "learning rate" control during training?
The learning rate controls how big each step is when the model adjusts its weights. A very large step can overshoot the best answer, while a very small step makes learning extremely slow. Choosing a sensible learning rate helps the model improve steadily.
Why do we often "normalise" or scale numbers (for example to the range 0 to 1) before feeding them to an AI model?
Different features can have very different sizes, like age (0-100) and income (thousands), and large numbers can unfairly dominate. Scaling them to a similar range, such as 0 to 1, helps the model treat each feature fairly and learn faster. This is a common first step in preparing data.
x = 30
x_min, x_max = 0, 100
scaled = (x - x_min) / (x_max - x_min) # 0.3How can a computer measure the straight-line distance between two points (x1,y1) and (x2,y2)?
It uses the distance formula, which comes from the Pythagorean theorem: distance = square root of ((x2-x1)^2 + (y2-y1)^2). AI uses distances to decide how similar two items are, since closer points are more alike. This idea powers many simple learning methods.
import math
d = math.sqrt((4-1)**2 + (5-1)**2) # 5.0The k-Nearest Neighbors method classifies a new point by looking at the k closest points. What maths idea does it mainly rely on?
It mainly relies on distance, finding which known examples are nearest to the new point. The new point is then given the most common label among its closest neighbours. The key idea is that similar things tend to be close together.
A sigmoid function squashes any number into a small range. What range is that?
The sigmoid function turns any input, even a very large or very negative one, into a number between 0 and 1. This is handy because the result can be read as a probability or a confidence. It is one common way a neuron decides how strongly to fire.
A model outputs a probability of 0.8 that an email is spam, and we use a threshold of 0.5. What is the decision?
Because 0.8 is greater than the threshold of 0.5, the model classifies the email as spam. A threshold is a cut-off value that turns a probability into a yes-or-no decision. Changing the threshold makes the model stricter or more relaxed.
prob = 0.8
is_spam = prob > 0.5 # TrueWhen a model gives probabilities for several classes (for example cat, dog, bird), what should all those probabilities add up to?
They should add up to 1, because together they cover every possible answer. For example 0.7 cat, 0.2 dog and 0.1 bird sums to 1.0. This lets the numbers be read as a proper share of confidence across the choices.
If a model's class probabilities are cat 0.7, dog 0.2, bird 0.1, which class does "argmax" choose?
Argmax picks the class with the highest probability, which here is cat at 0.7. It does not care about the exact values, only which one is largest. This is how a model turns a list of confidences into a single final answer.
probs = {'cat':0.7, 'dog':0.2, 'bird':0.1}
choice = max(probs, key=probs.get) # 'cat'What does it mean when a model is "overfitting"?
Overfitting means the model has basically memorised the training examples, including their noise, instead of learning the general pattern. It then performs well on data it has seen but poorly on new, unseen data. The goal is to learn patterns that work on examples the model has never met.
Why do we split our data into a "training set" and a "test set"?
We train the model on the training set and then check it on the test set, which it has never seen. This tells us whether the model truly learned the pattern or just memorised the answers. Testing on fresh data gives an honest measure of how well it will work in real life.
Two students score the same average on a test, but one set of scores is spread out and the other is close together. Which maths idea describes this spread?
The spread of values around the average is described by variance (or its square root, the standard deviation). A large spread means the numbers vary a lot, while a small spread means they are close to the mean. AI uses spread to understand how consistent or noisy data is.
If 3 out of 4 predictions are correct, what is this as a percentage?
You divide 3 by 4 to get 0.75 and then multiply by 100 to get 75 percent. Percentages are a way of expressing a fraction out of 100. AI results are very often reported as percentages so they are easy to compare.
pct = (3 / 4) * 100 # 75.0In AI maths, what is a matrix?
A matrix is a rectangular table of numbers arranged in rows and columns. AI uses matrices to store and process lots of numbers at once, such as the pixels of an image or the weights of a network. Doing maths on whole matrices lets computers work very efficiently.
What is "one-hot encoding" and why is it used?
One-hot encoding turns a category into a list of 0s with a single 1 marking the chosen category, for example red = [1,0,0], green = [0,1,0]. It is used because models work with numbers, not words, and it avoids pretending one category is bigger than another. Each category gets its own equal slot.
# colours: red, green, blue
red = [1, 0, 0]
green = [0, 1, 0]In a neuron, what is the job of the "bias" term that is added to the weighted sum?
The bias is an extra number added to the weighted sum that lets the neuron shift its output up or down. It works like the c in y = mx + c, allowing the line to move so it does not have to pass through zero. This gives the model more flexibility to fit the data.
weighted_sum = 4
bias = 1
output = weighted_sum + bias # 5If it has rained on 8 of the last 10 cloudy days, what is the estimated probability of rain given that it is cloudy?
This is a conditional probability: out of the 10 cloudy days, rain happened on 8, so the probability is 8/10 = 0.8, or 80 percent. Conditional probability asks how likely something is given that we already know another fact. AI uses this idea to update its beliefs as it gets more information.
Two variables are "positively correlated" when one tends to go up as the other goes up. Which example shows positive correlation?
Positive correlation means the two values rise and fall together, like hours studied and exam score. It does not prove one causes the other, only that they move in the same direction. AI uses correlation to spot useful relationships in data.
A piece of data doubles every step: 1, 2, 4, 8, 16... What kind of growth is this?
This is exponential growth, where the amount is multiplied by a fixed number (here 2) at each step rather than added to. Exponential growth becomes very large very quickly. Understanding it helps explain why some AI tasks need huge amounts of computation.
A logarithm answers the question "how many times do I multiply the base by itself to get a number?". What is log base 2 of 8?
Since 2 x 2 x 2 = 8, you multiply 2 by itself 3 times, so log base 2 of 8 is 3. Logarithms turn very big numbers into smaller, easier-to-handle ones, which is useful in AI maths and loss functions. They are the opposite of exponents.
import math
result = math.log2(8) # 3.0Why are the weights of a neural network usually set to small random numbers before training begins?
Random starting weights break symmetry so that different neurons can learn different things instead of all behaving identically. Training then gradually adjusts these random numbers into useful values. Starting from randomness is a normal and important part of how learning begins.
How many different 2-letter codes can you make using the 26 letters of the alphabet, if letters can repeat?
For each of the 2 positions you can choose any of 26 letters, so you multiply 26 x 26 = 676. This is the counting principle, where you multiply the number of choices for each position. AI uses such counting to understand how many possible outcomes a problem has.
total = 26 * 26 # 676Why do AI systems sometimes round numbers, such as showing 0.6667 as 0.67?
Rounding keeps results short and readable while staying close enough to the true value for the purpose. Computers cannot store infinitely long decimals, so some rounding is unavoidable. The trade-off is a tiny loss of precision in exchange for simpler numbers.
value = 2/3
rounded = round(value, 2) # 0.67To shrink a 600x400 image to half its width and height, what will the new size be?
Halving both the width and the height gives 300x200, keeping the same shape (aspect ratio). This uses the maths of ratios and proportion so the image does not look stretched. AI often resizes images this way so every input is the same size.
w, h = 600, 400
new = (w//2, h//2) # (300, 200)A grey pixel value is stored from 0 (black) to 255 (white). How can we scale a value of 255 to the range 0 to 1?
You divide the pixel value by 255, so 255 / 255 = 1.0 and, for example, 128 / 255 is about 0.5. This puts all pixels on the same 0-to-1 scale, which helps the model learn. It is a simple and very common way to prepare image data.
pixel = 255
scaled = pixel / 255 # 1.0The slope (gradient) tells the model how much the output changes when an input changes a little. Why is this so useful for learning?
The slope shows the direction and amount to change a weight to reduce the error, like knowing which way is downhill. Following the slope lets the model improve step by step instead of guessing randomly. This idea of using slopes is at the heart of how AI learns.
Imagine a fairness check where a model approves 90 percent of loans for one group but only 60 percent for another, equally-qualified group. What simple maths comparison reveals the problem?
Comparing the two approval rates, 90 percent versus 60 percent, shows a 30 percentage-point gap that suggests unfair bias. Even simple subtraction of rates can reveal when a model treats groups differently. Checking such numbers is an important part of building ethical AI.
gap = 90 - 60 # 30 percentage pointsRelated topics in Foundations & Concepts
Put it into practice with AI Learning
This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.
- Free
- No account
- Works offline