Python and maths for ML: where to start
The small set of NumPy, pandas and maths ideas that unlock machine learning.
Starting machine learning can feel like facing four subjects at once: programming, maths, statistics and the ML libraries themselves. You do not need to master all of them first. You need a small, well-chosen foundation, and the habit of building things as you learn. Here is a realistic order of attack.
What you actually need first
Python, at a working level. Not advanced software engineering; enough to read and write short scripts confidently.
- Variables, numbers, strings, lists, dictionaries, tuples and sets
if,for,while, and comprehensions- Functions, arguments and return values
- Reading and writing files
- Simple classes (mostly to understand libraries that use them)
- Reading error messages and using a debugger or print statements
The data stack:
- NumPy for arrays and fast numerical operations
- pandas for tables: loading, cleaning, filtering, grouping, joining
- Matplotlib (or a similar library) for plots
- scikit-learn for classic machine learning
The maths, in the order it pays off
You can learn most of it alongside code. Focus on intuition and application.
- Linear algebra basics: vectors, matrices, dot products, matrix multiplication and shapes. Everything in ML is arrays, and shape mistakes are the commonest bug.
- Calculus intuition: a derivative is a slope; a gradient points uphill. Training a model is walking downhill on an error surface.
- Probability and statistics: distributions, mean and variance, conditional probability, and what a sample tells you about a population.
- Optimisation ideas: loss functions, gradient descent, learning rate.
You do not need to prove theorems. You need to predict what code will do, such as the shape of a result, or what happens if the learning rate is too large.
A first project that teaches the whole loop
Small, end to end, on a public dataset such as house prices or a flower classification set.
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
df = pd.read_csv("data.csv")
X = df.drop(columns=["label"])
y = df["label"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=0, stratify=y
)
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
model.fit(X_train, y_train)
print(accuracy_score(y_test, model.predict(X_test)))
The point is not the score. It is practising the loop: load, look, clean, split, train, evaluate, interpret. Then change one thing and see what happens.
How to practise
- Type code, don't just read it. Break it on purpose and fix it.
- Print shapes constantly.
array.shapeanddf.head()are your best friends. - Work with real, messy data. Missing values and odd formats are the real curriculum.
- Plot before you model. A histogram or scatter plot reveals problems no metric will.
- Keep a notebook of what you learned in your own words.
Habits worth building early
- Split your data before you look for patterns, and keep a test set untouched.
- Start with a simple baseline (predict the average or the most common class) so you know what "better" means.
- Set random seeds so results are reproducible.
- Write small functions and test them on tiny inputs.
- Use version control from the first project.
Common mistakes
- Watching tutorials for weeks without building anything.
- Trying to learn all the maths before writing code.
- Jumping to deep learning before understanding a linear model and evaluation.
- Ignoring data cleaning.
- Judging a model by training accuracy.
A four-week starting plan
| Week | Focus | Build |
|---|---|---|
| 1 | Python basics, functions, files | A script that cleans a text file and counts words |
| 2 | NumPy and pandas | Load a dataset, summarise it, plot three charts |
| 3 | Vectors, matrices, gradients (intuition) | Fit a line to points with gradient descent by hand |
| 4 | scikit-learn and evaluation | The end-to-end project above, with a baseline and a held-out test set |
Adjust the pace to your time. What matters is that each week ends with something you built and can explain.
Where to go next
Once you can complete that loop comfortably, move on to model evaluation in more depth, then a first neural network. A structured course gives you feedback and a path; the habits above make any path work better.
Keep learning
How this is used in practice
Typical use cases
- Data cleaning: loading, reshaping and checking tables before any model.
- Baselines: a first scikit-learn model in a few lines.
- Reproducible notebooks and scripts.
General examples of where this idea is applied, not tied to a particular company.
Tools and infrastructure in this guide
Mapped to our tools and tech stack.
Further reading and tools
Official documentation, papers and code referred to in this guide. Links open in a new tab.
More guides
Book a call
Tell us your background and goal — we'll map a course path that fits.
Talk to an advisor