Data science is often sold as a set of tools: Python, SQL, dashboards and machine learning libraries. But the people who truly understand their models, and can explain why a prediction went wrong, are the ones who know the mathematics underneath. This roadmap shows which areas of maths matter most, in what order to learn them, and how each one appears in real data science work.
Stage 1: Foundations You Already Have
If you have completed Matric and FSc or A Level mathematics, you already own the starting toolkit:
- Algebra and functions: linear, quadratic, exponential and logarithmic functions describe trends, growth and transformations of data.
- Basic statistics: mean, median, mode, variance and standard deviation.
- Coordinate geometry: distances between points, which become distances between data records.
- Summation notation: \( \sum_{i=1}^{n} x_i \) appears in nearly every formula you will meet.
Before moving on, make sure you can comfortably manipulate logarithms, since log transforms, log-likelihoods and log-loss are everywhere.
Stage 2: Linear Algebra, the Language of Data
A dataset with \( n \) rows and \( p \) columns is a matrix \( X \) of size \( n \times p \). Linear algebra tells you how to work with it:
- Vectors and dot products: measure similarity, for example cosine similarity between documents.
- Matrix multiplication: every layer of a neural network computes \( W\mathbf{x} + \mathbf{b} \).
- Eigenvalues and eigenvectors: power principal component analysis (PCA), which compresses many variables into a few.
- Singular value decomposition: used in recommender systems and noise reduction.
Stage 3: Calculus and Optimisation
Training a model means choosing parameters that minimise a loss function. Calculus provides the gradient, the direction of steepest increase, and gradient descent moves the opposite way:
$$ \theta_{\text{new}} = \theta_{\text{old}} - \eta \, \nabla L(\theta_{\text{old}}), $$
where \( \eta \) is the learning rate. You need partial derivatives, the chain rule (which is exactly what backpropagation is) and some idea of convexity, which guarantees that a local minimum is the global one.
Stage 4: Probability and Statistics
Data are noisy, so every conclusion carries uncertainty. Key topics include random variables, the normal and binomial distributions, expectation, conditional probability, Bayes' theorem, sampling distributions, confidence intervals, hypothesis tests and regression.
Worked Example 1: Fitting a Regression Line by Hand
A small shop records advertising spend \( x \) (in thousand PKR) and weekly sales \( y \) (in thousand PKR):
| Week | \( x \) | \( y \) |
|---|---|---|
| 1 | 1 | 2 |
| 2 | 2 | 4 |
| 3 | 3 | 5 |
| 4 | 4 | 4 |
| 5 | 5 | 5 |
The least-squares line \( \hat{y} = b_0 + b_1 x \) minimises the sum of squared residuals and has
$$ b_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}, \qquad b_0 = \bar{y} - b_1 \bar{x}. $$
Step 1: Means. \( \bar{x} = 15/5 = 3 \) and \( \bar{y} = 20/5 = 4 \).
Step 2: Deviations and products. The values of \( (x_i - 3)(y_i - 4) \) are \( (-2)(-2) = 4 \), \( (-1)(0) = 0 \), \( (0)(1) = 0 \), \( (1)(0) = 0 \) and \( (2)(1) = 2 \), so \( S_{xy} = 6 \). The squared \( x \)-deviations are \( 4, 1, 0, 1, 4 \), so \( S_{xx} = 10 \).
Step 3: Coefficients.
$$ b_1 = \frac{6}{10} = 0.6, \qquad b_0 = 4 - 0.6(3) = 2.2. $$
Step 4: Goodness of fit. Predicted values are \( 2.8, 3.4, 4.0, 4.6, 5.2 \), giving residuals \( -0.8, 0.6, 1.0, -0.6, -0.2 \). The residual sum of squares is \( 0.64 + 0.36 + 1.00 + 0.36 + 0.04 = 2.4 \). The total sum of squares is \( \sum (y_i - 4)^2 = 4 + 0 + 1 + 0 + 1 = 6 \). Hence
$$ R^2 = 1 - \frac{2.4}{6} = 0.6. $$
Interpretation: each extra thousand rupees of advertising is associated with about PKR 600 more weekly sales, and the line explains 60% of the variation in sales. With only five points, we would be cautious: a confidence interval for the slope would be wide. In Python you can check this with numpy.polyfit(x, y, 1), and in R with lm(y ~ x).
Worked Example 2: Bayes' Theorem and the Base-Rate Trap
A screening model flags fraudulent bank transactions. Suppose 1% of transactions are fraudulent, the model catches 95% of frauds (sensitivity), and it wrongly flags 5% of genuine transactions (false positive rate). If a transaction is flagged, what is the probability it is really fraud?
Step 1: Write Bayes' theorem.
$$ P(F \mid +) = \frac{P(+ \mid F)\,P(F)}{P(+ \mid F)\,P(F) + P(+ \mid \bar{F})\,P(\bar{F})}. $$
Step 2: Substitute.
$$ P(F \mid +) = \frac{0.95 \times 0.01}{0.95 \times 0.01 + 0.05 \times 0.99} = \frac{0.0095}{0.0095 + 0.0495} = \frac{0.0095}{0.059}. $$
Step 3: Compute. \( P(F \mid +) \approx 0.161 \), or about 16%.
Sanity check with counts: out of 10,000 transactions, 100 are fraud and 95 are flagged; of the 9,900 genuine ones, 495 are flagged. So 95 of the 590 flagged transactions are fraud, and \( 95/590 \approx 0.161 \). Even a "95% accurate" model produces mostly false alarms when the event is rare. This is why data scientists report precision and recall instead of accuracy alone.
Stage 5: Advanced Topics for Research
Once the foundations are secure, the frontier opens up:
- Statistical learning theory: why models generalise, bias–variance trade-off, regularisation.
- Bayesian inference: priors, posteriors and Markov chain Monte Carlo.
- Information theory: entropy and cross-entropy, which define the loss functions of classifiers.
- Causal inference: distinguishing correlation from causation using experiments, instrumental variables and causal graphs.
- High-dimensional statistics: methods like the lasso when variables outnumber observations.
A Suggested Study Order
- Refresh algebra, functions and logarithms.
- Learn descriptive statistics and probability.
- Study linear algebra with a focus on matrices and eigenvectors.
- Learn multivariable calculus and gradient descent.
- Study inferential statistics and regression.
- Apply everything in projects with Python or R, then read research papers.
Practise each stage on real datasets, such as public data on weather, cricket scores or exam results, so the maths stays connected to meaning.
Did You Know?
- The method of least squares was published by Adrien-Marie Legendre in 1805, and Carl Friedrich Gauss claimed he had used it since 1795.
- Bayes' theorem is named after Thomas Bayes, whose essay was published in 1763, two years after his death.
- PCA was introduced by Karl Pearson in 1901, more than a century before "data science" became a job title.
Key Takeaways
- Linear algebra, calculus, probability and statistics are the four pillars of data science.
- Least-squares regression can be computed by hand from means, \( S_{xy} \) and \( S_{xx} \).
- Bayes' theorem shows why rare events produce many false positives, even with good models.
- Learn the maths in stages and connect each stage to a real dataset.
Want step-by-step help with statistics, regression, machine learning maths or a data science assignment? Amathify's experts and PhD scholars are a WhatsApp message or an Ask a Question form away.
Stuck on a problem or assignment?
Our experts and PhD scholars solve maths, physics and chemistry — step by step.