Data and modeling
Machine learning libraries for Python
Python's machine learning libraries each do one job well: NumPy for arrays, pandas for tables, scikit-learn for classical models, XGBoost or LightGBM for boosted trees, PyTorch for deep learning and statsmodels for statistical inference. Most projects combine three or four of them, with Matplotlib for charts.
How Python's machine learning libraries are used
Numerical computing with NumPy
NumPy arrays are the shared format underneath almost every Python data and ML library. Fast vectorised operations on them replace slow Python loops.
Real exampleArray programming with NumPy (Harris et al., Nature 2020)The paper reports that NumPy was an important part of the software stack used in the discovery of gravitational waves and the first imaging of a black hole.
Working with tables in pandas
pandas DataFrames handle loading, cleaning, joining and summarising tabular data before modelling. Most ML projects in Python start and end in pandas.
Real exampleData Structures for Statistical Computing in Python (McKinney, SciPy 2010)The paper introduces pandas as a library for working with datasets common in finance and statistics, providing building blocks for statistical models.
Classical machine learning with scikit-learn
scikit-learn gives one consistent interface for preprocessing, dozens of models, cross-validation and metrics. It covers most tabular problems that do not need deep learning.
Real exampleScikit-learn: Machine Learning in Python (Pedregosa et al., JMLR 2011)The paper presents scikit-learn as a Python module integrating a wide range of machine learning algorithms with an emphasis on ease of use.
Deep learning with PyTorch
PyTorch provides tensors on GPUs, automatic differentiation and building blocks for neural networks. It is used for images, text, audio and large language models.
Real examplePyTorch: An Imperative Style, High-Performance Deep Learning Library (Paszke et al., 2019)The paper describes PyTorch's design, which runs models as ordinary Python code while keeping performance through GPU acceleration.
Statistical models with statsmodels
statsmodels fits regression and time series models with standard errors, tests and diagnostics, which matter when the goal is inference rather than only prediction.
Real exampleStatsmodels: Econometric and Statistical Modeling with Python (Seabold and Perktold, SciPy 2010)The paper introduces statsmodels, a library for statistical and econometric modelling in Python.
Can you learn Python's machine learning libraries?
Yes. Learn them in the order you will use them: Python, then NumPy and pandas, then Matplotlib for charts, then scikit-learn. Add XGBoost or LightGBM for tabular work and PyTorch when you move into deep learning.
- PythonLearn the core language, functions, data structures and classes, which all libraries build on.Learn it in Python
- NumPy, pandas and MatplotlibWork with arrays and tables, and plot data, before fitting any model.Learn it in Data Tools
- scikit-learnUse the fit, predict and transform pattern, pipelines and cross-validation across many models.Learn it in Machine Learning
- PyTorchBuild and train neural networks with tensors, autograd and training loops.Learn it in Deep Learning
Where to go after learning the libraries
If you already work in the field
If you already analyse data in Excel, R, MATLAB or Stata, the ideas carry over and only the syntax changes. Redo one familiar analysis in pandas and scikit-learn and compare the results with your existing tool.
If you come from data science or ML
If you know the theory but not the tools, work through each library's official tutorial and then build one small end-to-end project. Read the scikit-learn user guide on pipelines and model evaluation closely.
Roles that do this workData scientistMachine learning engineerData analystResearch software engineer
Tools you will use
| Tool | What you use it for |
|---|---|
| NumPy | Store numbers in fast n-dimensional arrays, the base layer every other library builds on. |
| pandas | Load, clean and join tables, then hand feature columns to a model. |
| scikit-learn | Fit classical models, build pipelines and cross-validate through one fit and predict interface. |
| XGBoost | Get strong accuracy on tabular data with gradient-boosted trees. |
| PyTorch | Build and train neural networks for images, text and custom models, on CPU or GPU. |
| statsmodels | Fit regression and time-series models with standard errors and hypothesis tests. |
Public data to practise on
- Breast Cancer Wisconsin (Diagnostic) (UCI): Cell-nucleus measurements from breast-mass images labelled benign or malignant, a quick scikit-learn and XGBoost exercise.
- CIFAR-10: Small colour images in ten classes, the usual first dataset for training a PyTorch image classifier.
Your first project
Download the Breast Cancer Wisconsin (Diagnostic) dataset, fit logistic regression in scikit-learn and a classifier in XGBoost, and compare both with a majority-class baseline using ROC AUC under 5-fold cross-validation.
Common questions
Which Python library is best for machine learning?
For most tabular problems, scikit-learn, with XGBoost or LightGBM for boosted trees. For deep learning, PyTorch is the most widely used in research. Most projects use several libraries together.
Should I learn TensorFlow or PyTorch?
Both work. PyTorch is the more common choice in research and many new projects, while TensorFlow and Keras remain in use in some production and mobile settings. The concepts transfer between them.
Do I need to learn NumPy before pandas?
A little NumPy helps, because pandas is built on it and scikit-learn returns NumPy arrays. Learn array basics, then spend most of your time in pandas.
What is the difference between scikit-learn and statsmodels?
scikit-learn focuses on prediction and model evaluation. statsmodels focuses on statistical inference, with p-values, confidence intervals and diagnostics for regression and time series models.
Courses for these skills
- Practical Machine Learning in PythonStudy distances, clustering and evaluating unsupervised results.51 published lessons · more lessons in production
- Data Tools: NumPy, pandas, Matplotlib and scikit-learnInspect feature scales and representative rows.23 published lessons · all planned lessons open
- Deep Learning with PyTorchStudy CNNs, representations and image-model evaluation.Syllabus available · lessons open as produced
- Python for AI and Machine LearningBuild the basic programming skills used to handle image records.33 published lessons · all planned lessons open
New to programming or maths? Start with Python, or follow the machine learning path in order. Published lessons are free to read; compare Free and Pro.