Python libraries for AI: which ones to focus on for your coursework
For university AI and machine learning coursework, you should focus your revision on NumPy for numerical computation, pandas for data manipulation, scikit-learn for traditional algorithms, and PyTorch for deep learning. Mastering these four core libraries allows you to handle the entire pipeline from raw data to a trained model, which is exactly what examiners expect to see. Spending your time understanding the underlying logic of these specific tools will yield much higher marks than trying to memorise the documentation of every Python package available.
When you transition from learning basic Python to building machine learning models for a university module, the sheer volume of available third-party packages can feel overwhelming. Many students make the mistake of trying to learn a little bit of everything. As a practitioner marking exam papers and coursework, I can tell you that breadth is far less valuable than depth. Examiners want to see that you understand how data flows through a machine learning pipeline.
We look for evidence that you can ingest raw data, clean it, extract features, train a suitable model, and evaluate its performance. You only need a handful of carefully selected tools to achieve this. By restricting your focus to the industry standards, you reduce your cognitive load and give yourself more time to understand the mathematical and algorithmic principles that actually dictate your final grade.
NumPy and pandas: the foundation of data preparation
Before you can train an artificial intelligence model, you must prepare your data. In almost all university coursework, this data will be provided in a tabular format, such as a CSV file containing housing prices or medical records. Your first step is to manipulate this data, and for this task, pandas is the standard tool. pandas provides the DataFrame object, which allows you to filter rows, handle missing values, and merge datasets with a syntax that reads much like SQL.
Beneath pandas lies NumPy, the library that handles numerical computation in Python. Machine learning models do not understand text or raw tables; they understand matrices and vectors. NumPy provides the multidimensional array object, which is highly optimised for linear algebra operations. When you pass a pandas DataFrame into a machine learning algorithm, it is usually converted into a NumPy array behind the scenes.
A common coursework task is normalising a dataset so that all features have a mean of zero and a standard deviation of one. Using raw Python for-loops to calculate this across millions of rows would be computationally disastrous. With NumPy, you can apply vectorised operations. You simply subtract the mean and divide by the standard deviation for the entire array in a single line of code. Examiners specifically look for this vectorised approach because it demonstrates that you understand how to write computationally efficient code, a core requirement for processing large-scale AI datasets.
In a written exam, you might be asked to explain how to prepare a dataset containing missing values and categorical text. A high-scoring answer will state that you would use pandas to fill or drop the missing values (imputation), convert the categorical text into numerical codes using one-hot encoding, and then rely on NumPy arrays to feed this clean, purely numerical matrix into your chosen algorithm.
scikit-learn: mastering traditional machine learning
Once your data is clean and formatted as a numerical array, you need to train a model. For traditional machine learning (anything that is not a deep neural network), scikit-learn is the only library you need to study. It covers classification, regression, clustering, and dimensionality reduction. Whether your coursework requires a Support Vector Machine, a Random Forest, or K-Means clustering, scikit-learn provides a highly consistent interface to implement it.
The brilliance of scikit-learn is its uniform application programming
interface. Every model in the library shares the same core methods:
fit() to train the model on your data, and
predict() to generate outputs for new, unseen data. Data
transformation tools, such as scalers or feature extractors, use
fit_transform(). This consistency means that once you learn
how to train a basic logistic regression model, you already know the
syntax to train a complex gradient boosting machine.
A critical concept tested in almost every machine learning module is
data leakage (where information from the test set accidentally leaks
into the training process). Students frequently lose marks by scaling
their entire dataset before splitting it into training and testing
subsets. To avoid this, scikit-learn provides the Pipeline class. A
pipeline chains together your preprocessing steps and your final model.
When you call fit() on the pipeline, it ensures that
scaling metrics are calculated exclusively on the training data.
If you are asked to design a machine learning experiment in an exam, explicitly mentioning the use of a scikit-learn Pipeline to prevent data leakage will immediately elevate your answer. It shows the examiner that you are thinking like a practitioner who anticipates real-world experimental errors, rather than a student who is just copying code snippets from a lecture slide.
PyTorch vs TensorFlow: choosing your deep learning framework
When your coursework moves into deep learning, computer vision, or natural language processing, traditional algorithms are no longer sufficient. You need to build artificial neural networks, which require specialised libraries capable of running operations on a Graphics Processing Unit (GPU) and calculating complex gradients automatically. The two dominant choices are PyTorch and TensorFlow.
Historically, TensorFlow was the industry standard, while PyTorch was favoured in academic research. Today, PyTorch has largely won the popularity contest in both domains due to its intuitive design. PyTorch uses dynamic computation graphs, meaning the network behaves like standard Python code. You can insert print statements anywhere inside your neural network to see exactly what the data looks like at that specific layer. This makes debugging significantly easier for students.
In PyTorch, building a neural network involves creating a class that
inherits from nn.Module. You define your layers (such as
linear transformations or convolutional filters) in the initialization
method, and then you define how data flows through those layers in the
forward() method. You do not need to write the complex
calculus for backpropagation yourself; PyTorch’s autograd engine tracks
every operation and calculates the gradients for you when you call
backward() on your loss function.
For your exam revision, pick one framework and stick to it. I strongly advise focusing on PyTorch unless your university specifically mandates TensorFlow. If an exam question asks you to design a convolutional neural network for image classification, you should be able to sketch out the architecture conceptually and explain how a tensor (the PyTorch equivalent of a NumPy array) passes through convolutional layers, pooling layers, and fully connected layers to produce a final prediction.
Matplotlib and Seaborn: visualising your results
Training a model is only half of the assignment; you must also evaluate and communicate its performance. A coursework report that just prints a final accuracy score will not achieve a top grade. You need to present visual evidence of your data distributions, the training progress, and the areas where your model makes errors. Matplotlib is the fundamental plotting library in Python, and Seaborn is an extension built on top of it that makes statistical graphics much easier to generate.
Matplotlib gives you complete control over every line, axis, and label on a chart. It is highly flexible but can require a lot of code for simple tasks. Seaborn simplifies this by providing high-level functions that work directly with pandas DataFrames. For example, if you want to see how the different features in your dataset correlate with one another, Seaborn can generate a colour-coded correlation heatmap in a single line of code.
One specific visualisation you should always include in a classification coursework is a confusion matrix. This shows exactly how many instances of Class A were incorrectly predicted as Class B. Plotting this as a heatmap using Seaborn provides a clear, professional graphic that proves you understand the difference between overall accuracy and specific class precision. In an exam, if asked how you would evaluate a model on an imbalanced dataset, mentioning that you would visually inspect the confusion matrix rather than relying on a single accuracy metric will secure high marks.
How to answer this in an exam
When university exams ask questions about Python libraries, they are rarely testing your ability to remember exact syntax. An examiner does not care if you forget a specific parameter name in a function call. What the mark scheme rewards is your architectural understanding and your ability to justify technical choices.
If a question asks you to outline a solution for a predictive modelling problem, you should structure your answer chronologically. State that you will use pandas for initial data cleaning, NumPy for matrix transformations, and scikit-learn for the modelling. Crucially, you must justify these choices based on the scenario provided. If the dataset is small and tabular, explain that using scikit-learn to train a Random Forest is far more appropriate and computationally efficient than building a deep neural network in PyTorch.
The Full Marks Press Programming for AI guide covers this with worked exam questions, showing you exactly how to structure your written answers to pick up maximum marks for technical justification. Whenever you mention a library, pair it with the specific problem it solves (for example, “I would use scikit-learn’s GridSearchCV to automate the hyperparameter tuning process efficiently”).
Frequently asked questions
Do I need to memorise exact Python syntax for a written exam? No, university exams generally test conceptual understanding and algorithmic logic. Pseudocode or conceptually accurate Python sketches are usually perfectly acceptable, provided you name the correct algorithms and demonstrate a logical flow of data.
Why should I use pandas if I can just read a CSV file with standard Python? Standard Python requires writing complex loops to parse and clean data. pandas handles missing data, type conversions, and filtering automatically, saving time and significantly reducing the likelihood of introducing bugs into your preprocessing pipeline.
Can I use PyTorch for everything, including simple regression? You can, but it is highly inefficient. Building a neural network for a simple linear regression task is like using a sledgehammer to crack a nut. scikit-learn is much faster and requires far less code for traditional, simpler machine learning tasks.
How do I prove my code is computationally efficient in coursework? Avoid raw Python for-loops whenever you are processing data. Apply NumPy’s vectorised operations and pandas’ built-in aggregation functions, and explicitly mention in your report that you chose these methods to reduce computational complexity and execution time.
You can download a free copy of our revision guides at fullmarkspress.com/free.