Course Content
Statistics & Math for AI/ML Interviews
8 sections · 30 lessons
What is the mean, and how is it used in model evaluation or dataset analysis?
What you need to know
The idea before the formula
Think of the mean as the "fair share" value. If five friends pool their money and split it equally, each person's share is the mean. It is the single number that, repeated for every item, gives the same total.
mean = (x1 + x2 + ... + xn) / nWorked example. Five students score 62, 70, 75, 81 and 92 in an exam. The total is 380. Divide by 5 and the mean is 76.
Where the mean shows up in dataset analysis
- Typical value of a feature. The mean delivery time is 32 minutes; the mean age of users is 29.
- Scale check. If one column has a mean of 0.4 and another a mean of 45,000, you need to scale before using distance-based models like k-NN or before gradient descent.
- Centring. Standardisation subtracts the mean from each value, so the feature is centred on zero.
- Missing values. Filling blanks with the mean is quick, but only safe when the column is roughly symmetric.
Where the mean shows up in model evaluation
Most metrics are a mean of something computed per example.
MAE = mean of |prediction - actual|MSE = mean of (prediction - actual)^2accuracy = mean of (1 if correct else 0)Here is a delivery-time model checked on five orders.
1import numpy as np23y_true = np.array([30, 25, 40, 35, 20]) # actual delivery minutes4y_pred = np.array([28, 28, 39, 45, 25]) # model's predictions5errors = y_pred - y_true67print("errors:", errors)8print("MAE :", np.mean(np.abs(errors)))9print("MSE :", np.mean(errors ** 2))10print("bias:", np.mean(errors))errors: [-2 3 -1 10 5]MAE : 4.2MSE : 27.8bias: 3.0The MAE says a typical prediction is off by about 4 minutes. The MSE is bigger because squaring punishes the one 10-minute miss heavily (100 out of the 139 total). The mean of the raw errors, called bias, is +3: the model predicts too late on average. We also average metrics across cross-validation folds, which is one more use of the mean.
A real-life example
Cricket batting averages show that "the mean" depends on what you divide by. A batter scores 45, 0, 102 not out, 30 and 23 not out across five innings. That is 200 runs.
- Runs per innings: 200 / 5 = 40.
- Batting average: 200 / 3 dismissals = 66.7, because official batting average divides by the number of times the batter was out, not by innings.
The same idea appears in ML. "Average accuracy" can mean the mean over all examples or the mean of per-class accuracies (balanced accuracy). On an imbalanced dataset these two numbers can be very different, so always say what you averaged over.
A production case: an e-commerce team reports "average order value is ₹7,574". When they look, six orders were ₹400–600 and one was a ₹50,000 bulk order. The mean describes nobody. The median (₹520) is the honest typical value.
Follow-up questions to expect
- "Why is the mean sensitive to outliers?" — Every value is added into the total with equal weight, so one huge value moves the total, and therefore the mean, by a lot. The median only cares about the middle position.
- "What is a weighted mean?" — Each value is multiplied by a weight before summing, and you divide by the total weight. Averaging per-class F1 scores by class size (weighted F1) is an example.
- "Is MSE or MAE better?" — MSE punishes large errors more, so use it when big misses are costly; MAE is more robust when the data has outliers you do not want to dominate training.