
The best machine learning libraries in Python depend on the type of data you work with and the task you need to solve. For traditional tabular data, Scikit-learn, XGBoost, and LightGBM are the standard choices for classification, regression, and predictive modelling, while PyTorch and TensorFlow lead deep learning work such as computer vision and large language models. Hugging Face Transformers and LangChain extend this further into modern generative AI and LLM-powered applications.
These tools sit on top of foundational data libraries like NumPy and Pandas, which handle data preparation and numerical computing before any model is trained. Together, they provide ready-to-use algorithms and frameworks to build, train, evaluate, and deploy models without coding every component from scratch. Choosing the right one comes down to your data type, the machine learning task, and how much control you need over the model.

NumPy is a Python library for numerical computing that provides efficient multidimensional arrays and mathematical operations. Its core ndarray structure makes it easier to store, manipulate, and perform calculations on numerical data across different dimensions.
NumPy is widely used in machine learning for data preparation, feature manipulation, matrix operations, and numerical calculations. Features such as vectorised operations and broadcasting allow calculations to be performed efficiently across large arrays, while universal functions (ufuncs) provide optimised operations for common mathematical tasks.
NumPy's ndarray is the structure used by NumPy for keeping and handling numbers. It can hold data in one or more dimensions, which makes it good for holding vectors, matrices and larger sets of numbers that are used in machine learning.
Unlike Python lists, ndarray is built for numeric work and lets you do calculations directly on all its entries. It also supports actions like indexing, slicing, reshaping, and gathering totals, which are often needed when getting data ready for machine learning models.
Broadcasting allows NumPy to perform operations between arrays that have different but compatible shapes. Instead of requiring the arrays to have exactly the same dimensions, NumPy automatically adjusts how the operation is applied based on their shapes.
This is particularly useful when the same value or a smaller array needs to be applied across a larger dataset. For example, a value can be added to every element in an array without manually creating a new array of repeated values, simplifying numerical calculations and data transformations.
Vectorization allows mathematical operations to be applied to an entire array at once rather than processing each value individually through Python loops. This results in shorter and more efficient code when working with numerical datasets.
In machine learning workflows, vectorization is useful for operations such as transforming features, performing mathematical calculations, and preparing numerical data. By operating directly on arrays, NumPy can handle these calculations more efficiently than repeatedly processing individual elements.
Universal functions, or ufuncs, are NumPy functions designed to perform element-wise operations on arrays. They include mathematical operations such as addition, multiplication, square roots, exponential calculations, and other commonly used numerical functions.
Ufuncs can operate on individual values as well as entire arrays while following NumPy's broadcasting rules. This makes it easier to apply the same mathematical operation across large datasets without writing separate loops or functions for each element.
ndarray, an efficient structure for storing and manipulating numerical data across one or more dimensions. It supports operations such as indexing, slicing, reshaping, and mathematical calculations on arrays.NumPy is commonly used for numerical calculations, data preprocessing, simulations, signal processing, and image manipulation. It can help clean, transform, reshape, and calculate values in datasets before the data is passed to a machine learning model. Its arrays also work closely with many Python libraries used for machine learning, data analysis, and scientific computing.
import numpy as np
features = np.array([10, 20, 30, 40])
scaled_features = features / np.max(features)
print(scaled_features)Here, NumPy creates an ndarray and uses vectorized operations to divide every value by the maximum value in the array. This demonstrates how NumPy can quickly transform numerical features during machine learning data preprocessing.
NumPy provides the numerical foundation needed for many machine learning workflows, from preparing and transforming datasets to performing mathematical and matrix-based operations. Its efficient arrays, broadcasting, vectorization, and mathematical functions make it useful for handling numerical computations before data reaches a machine learning model. Since many tools in the Python data science ecosystem work closely with NumPy arrays, understanding NumPy also provides a strong foundation for working with other machine learning and data analysis libraries.

Scikit-learn is a Python machine learning library that provides tools for building, training, evaluating, and applying machine learning models. It supports common machine learning tasks such as classification, regression, clustering, dimensionality reduction, and model selection.
Scikit-learn provides a consistent interface for working with different machine learning algorithms. Its tools can be used to prepare datasets, train models, evaluate their performance, and make predictions without having to implement each algorithm from scratch.
Estimators are Scikit-learn objects that implement machine learning algorithms or data transformation methods. They provide methods such as fit() learning patterns or parameters from data and, depending on the estimator, methods such as predict() working with new data.
For example, a classification algorithm can be used fit() to learn from training data and predict() to classify new observations. This common interface makes it easier to work with different algorithms using a similar workflow.
Transformers are Scikit-learn tools used to modify or prepare data before it is passed to a machine learning model. They can perform tasks such as feature scaling, encoding categorical values, imputing missing values, and transforming numerical features.
Transformers are commonly used fit() to learn the required transformation from the training data and transform() to apply it. This helps keep data preparation separate from model training and makes preprocessing steps easier to manage.
Scikit-learn provides tools for measuring how well a machine learning model performs on data. Depending on the type of problem, different evaluation metrics can be used, such as accuracy, precision, recall, F1-score, mean squared error, and R² score.
These evaluation tools help compare model predictions with the actual values and determine whether a model is performing appropriately for a particular machine learning task.
Scikit-learn includes tools for selecting and improving machine learning models. Techniques such as train-test splitting, cross-validation, and hyperparameter tuning can be used to evaluate models and identify suitable configurations.
For example, it train_test_split() can divide a dataset into training and testing sets, while tools such as it GridSearchCV can test different parameter combinations to find a suitable model configuration.
fit(), predict(), and transform(), making it easier to work with different models and preprocessing tools using a similar workflow.Scikit-learn is commonly used throughout the machine learning workflow, from preparing data to training and evaluating models. It provides algorithms for classification, regression, clustering, dimensionality reduction, and other common machine learning tasks.
It can also be used alongside libraries such as NumPy and pandas. NumPy provides numerical arrays and calculations, while pandas is commonly used for handling tabular data. Scikit-learn can then use this prepared data for preprocessing, model training, evaluation, and prediction.
The following example demonstrates how Scikit-learn can be used to train a simple classification model and make predictions:
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
X = [[20], [25], [30], [35], [40], [45]]
y = [0, 0, 0, 1, 1, 1]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(predictions)Here, X contains the input features, while y contains the corresponding class labels. Scikit-learn's train_test_split() divides the data into training and testing sets. The DecisionTreeClassifier is then trained using the fit() method and used to classify new data with predict().
Scikit-learn provides the tools needed to build and evaluate machine learning models in Python. Its consistent workflow makes it easier to prepare data, train models, make predictions, and evaluate results across different machine learning tasks. When used with libraries such as NumPy and pandas, it forms an important part of the Python machine learning ecosystem.

TensorFlow is an open-source machine learning framework used to build, train, and deploy machine learning and deep learning models. It provides tools for working with numerical data, neural networks, model training, and large-scale machine learning workflows.
TensorFlow uses tensors as its primary data structure for representing numerical data. It also provides APIs such as Keras for building neural networks and supports tasks such as image classification, natural language processing, time-series analysis, and other deep learning applications.
Tensors are multidimensional arrays used by TensorFlow to represent and process numerical data. They can have different numbers of dimensions depending on the type of data being handled.
For example, a single value can be represented as a scalar, a list of values as a vector, and image or batch data as higher-dimensional tensors. Tensor operations form the basis of calculations performed by TensorFlow models.
TensorFlow provides tools for creating neural networks made up of layers of interconnected nodes. Each layer processes the input data and passes the results to the next layer to learn patterns from the training data.
Neural networks can be used for tasks such as image classification, text processing, prediction, and other machine learning problems.
Model training is the process of teaching a machine learning model to identify patterns in training data. TensorFlow provides methods for defining a model, selecting a loss function and optimiser, and training the model over multiple iterations.
The fit() method is commonly used to train a model on available training data.
Keras is a high-level API integrated with TensorFlow that simplifies the process of building and training neural networks. It provides ready-to-use layers, model structures, optimisers, and training methods.
Using Keras, developers can create neural network models with fewer lines of code while still using TensorFlow's underlying machine learning capabilities.\
compile(), fit(), and evaluate(). This supports different loss functions, optimisers, and performance metrics.TensorFlow is commonly used for developing deep learning models that work with large and complex datasets. It supports applications such as image and speech recognition, natural language processing, recommendation systems, and time-series prediction.
It can work with data prepared using libraries such as NumPy and pandas, while Keras provides a simpler interface for creating and training neural networks within the TensorFlow ecosystem.
The following example demonstrates how TensorFlow can be used to build and train a simple neural network for classification:
import tensorflow as tf
X = [[20], [25], [30], [35], [40], [45]]
y = [0, 0, 0, 1, 1, 1]
model = tf.keras.Sequential([
tf.keras.layers.Dense(8, activation="relu"),
tf.keras.layers.Dense(1, activation="sigmoid")
])
model.compile(
optimizer="adam",
loss="binary_crossentropy",
metrics=["accuracy"]
)
model.fit(X, y, epochs=20, verbose=0)
predictions = model.predict([[32], [42]])
print(predictions)Here, the Sequential model contains two neural network layers. The first layer uses the ReLU activation function to process the input, while the second uses sigmoid to produce a classification output. The compile() method configures the model, and fit() trains it using the provided data. The trained model can then use predict() to generate outputs for new input values.
TensorFlow provides tools for building, training, and deploying machine learning and deep learning models. Its tensor-based operations, neural network layers, and Keras API make it useful for developing models for tasks such as classification, image processing, and natural language processing.

PyTorch is an open-source machine learning framework used to build, train, and deploy machine learning and deep learning models. It provides tools for working with tensors, neural networks, automatic differentiation, and model optimisation.
PyTorch is widely used for developing deep learning models for tasks such as image recognition, natural language processing, computer vision, and other complex machine learning applications. Its flexible approach to model development makes it useful for both research and practical machine learning projects.
Tensors are PyTorch's primary data structure for storing and processing numerical data. Similar to NumPy arrays, tensors can represent data in multiple dimensions and can be used for mathematical operations required during model training.
PyTorch tensors can also be processed using GPUs, which can speed up computations for large datasets and deep learning models.
PyTorch provides the torch.nn module for creating neural networks using layers, activation functions, and other components. Developers can define how data moves through different layers of a model and customise the architecture according to the machine learning task.
These neural networks can be used for tasks such as classification, prediction, image processing, and natural language processing.
PyTorch includes automatic differentiation through its autograd system. It automatically calculates gradients needed to update a model's parameters during training.
This reduces the need to manually calculate derivatives and allows neural networks to be trained using optimisation algorithms such as gradient descent.
PyTorch provides tools for training models by combining data, neural network architectures, loss functions, and optimisers. The model processes training data, calculates its error, and updates its parameters based on the calculated gradients.
This process is repeated across multiple training iterations until the model learns useful patterns from the data.
torch.nn and other components for building neural networks with layers, activation functions, loss functions, and custom architectures for different machine learning tasks.autograd system to automatically calculate gradients during model training. This simplifies the process of updating model parameters through optimisation algorithms.PyTorch is commonly used for developing and training deep learning models, particularly for applications involving images, text, audio, and other complex data. It provides tools for creating custom neural network architectures and controlling different parts of the training process.
PyTorch can also work with libraries such as NumPy and pandas for data preparation, while its tensor and neural network tools handle model training and numerical computations.
The following example demonstrates how PyTorch can be used to create and train a simple neural network for classification:
import torch
import torch.nn as nn
X = torch.tensor([[20.0], [25.0], [30.0], [35.0], [40.0], [45.0]])
y = torch.tensor([[0.0], [0.0], [0.0], [1.0], [1.0], [1.0]])
model = nn.Sequential(
nn.Linear(1, 8),
nn.ReLU(),
nn.Linear(8, 1),
nn.Sigmoid()
)
loss_function = nn.BCELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
for _ in range(100):
predictions = model(X)
loss = loss_function(predictions, y)
optimizer.zero_grad()
loss.backward()
optimizer.step()
new_data = torch.tensor([[32.0], [42.0]])
predictions = model(new_data)
print(predictions)Here, PyTorch first converts the input data into tensors. The Sequential model contains two linear layers with a ReLU activation function between them. BCELoss() measures the difference between the model's predictions and the actual labels, while the Adam optimiser updates the model's parameters during training.
The backward() method calculates the gradients required for learning, and step() updates the model based on those gradients. After training, the model uses new input data to generate predictions.
PyTorch provides flexible tools for building and training deep learning models. Its tensors, neural network modules, automatic differentiation, and optimisation tools make it useful for developing models for tasks such as classification, computer vision, and natural language processing.

XGBoost is an open-source machine learning library designed for gradient boosting and is commonly used for classification, regression, and ranking tasks. It builds models by combining multiple decision trees, with each new tree helping improve the errors made by the previous trees.
XGBoost is widely used for structured or tabular data because it can handle complex relationships between features and target values. It also provides features such as regularisation, missing-value handling, and support for different model objectives, making it useful for a range of machine learning applications.
Gradient boosting is a machine learning technique that builds an ensemble of decision trees sequentially. Each new tree focuses on reducing the errors made by the existing model, gradually improving the overall predictions.
XGBoost uses this approach to build models that can capture complex patterns in data. The process continues across multiple trees until the model reaches the required level of performance or a specified number of boosting rounds.
Decision trees are the basic building blocks used by XGBoost. Each tree makes a series of decisions based on input features and produces a prediction at the end of the path.
Instead of relying on a single tree, XGBoost combines predictions from many trees. This ensemble approach allows the model to learn more complex relationships within the dataset.
Regularisation helps control model complexity and can reduce overfitting. XGBoost provides regularisation techniques that can limit how complex individual trees become and how strongly they contribute to the final model.
This is useful when a model performs very well on training data but needs to maintain its performance when applied to unseen data.
The learning rate controls how much each new tree contributes to the overall model. A smaller learning rate generally requires more boosting rounds, while a larger learning rate can require fewer rounds.
These settings can be adjusted to control how quickly the model learns from the training data and how complex the final model becomes.
Gradient-boosted trees: Builds an ensemble of decision trees sequentially, with each new tree learning from the errors of previous trees to improve the model's predictions.
Regularisation: Includes L1 and L2 regularisation techniques that help control model complexity and reduce the risk of overfitting on training data.
Missing-value handling: Can automatically handle missing values during tree construction, reducing the need for manual handling of every missing value before training.
Model tuning: Provides parameters such as learning rate, tree depth, and number of boosting rounds that can be adjusted to control model complexity and improve prediction performance
XGBoost is widely used for classification, regression, ranking, and predictive modelling. It can work with structured datasets containing numerical and categorical information after appropriate preprocessing.
It is commonly applied to problems such as customer classification, sales prediction, risk assessment, fraud detection, and other tasks involving tabular data. Its combination of boosting, regularisation, and efficient tree-based learning makes it suitable for many supervised machine learning workflows.
The following example demonstrates how XGBoost can be used to train a classification model and make predictions:
from xgboost import XGBClassifier
X = [[20], [25], [30], [35], [40], [45]]
y = [0, 0, 0, 1, 1, 1]
model = XGBClassifier(
n_estimators=50,
max_depth=3,
learning_rate=0.1,
random_state=42
)
model.fit(X, y)
predictions = model.predict([[32], [42]])
print(predictions)Here, X contains the input features and y contains the corresponding class labels. XGBClassifier creates the classification model, while fit() trains it using the available data. The predict() method then uses the trained model to classify new input values.
This example demonstrates the basic XGBoost workflow of preparing data, configuring a model, training it, and generating predictions.
XGBoost provides a powerful approach to machine learning using gradient-boosted decision trees. Its support for classification, regression, regularisation, and model tuning makes it useful for working with structured datasets and complex prediction tasks.

LightGBM is an open-source machine learning framework developed by Microsoft for gradient boosting. It is commonly used for classification, regression, and ranking tasks, particularly when working with large structured or tabular datasets.
LightGBM builds decision tree-based models using gradient boosting and is designed to train models efficiently while using relatively low memory. It uses techniques such as histogram-based learning and leaf-wise tree growth to improve training efficiency and model performance.
Gradient boosting builds a model by combining multiple decision trees sequentially. Each new tree focuses on reducing the errors made by the existing model, allowing the overall model to improve over successive boosting rounds.
LightGBM applies gradient boosting to learn complex relationships between input features and target values.
LightGBM uses leaf-wise tree growth, where the algorithm selects the leaf that provides the greatest reduction in the model's loss and splits it further.
This approach can help the model reduce errors efficiently, although parameters such as maximum tree depth may be used to control model complexity and reduce overfitting.
LightGBM groups continuous feature values into discrete bins instead of evaluating every possible split value. This reduces the amount of computation required when building decision trees.
Histogram-based learning helps LightGBM train efficiently, particularly when working with large datasets containing many features.
LightGBM can work directly with categorical features when they are provided in the appropriate format. This can reduce the need for extensive preprocessing, such as manually converting every categorical feature into separate numerical columns.
This feature is particularly useful when working with structured datasets containing categories such as product types, regions, or customer segments.
LightGBM is commonly used for classification, regression, and ranking problems involving structured or tabular data. It can be applied to tasks such as predicting categories, estimating numerical values, and ranking search or recommendation results.
It can also work alongside libraries such as NumPy, pandas, and Scikit-learn. These libraries can be used to prepare and manage data, while LightGBM handles model training and prediction.
The following example demonstrates how LightGBM can be used to train a simple classification model and make predictions:
from lightgbm import LGBMClassifier
X = [[20], [25], [30], [35], [40], [45]]
y = [0, 0, 0, 1, 1, 1]
model = LGBMClassifier(
n_estimators=50,
learning_rate=0.1,
max_depth=3,
random_state=42,
verbosity=-1
)
model.fit(X, y)
predictions = model.predict([[32], [42]])
print(predictions)Here, X contains the input features and y contains the corresponding class labels. LGBMClassifier creates the classification model, while fit() trains the model using the available data. The predict() method then uses the trained model to classify new input values.
This example demonstrates the basic LightGBM workflow of preparing data, configuring a model, training it, and generating predictions.
LightGBM provides an efficient approach to gradient boosting for machine learning tasks involving structured data. Its leaf-wise tree growth, histogram-based learning, and support for categorical features make it useful for classification, regression, and ranking problems, particularly with large datasets.

Keras is a high-level deep learning API used to build, train, and evaluate neural network models. It provides a simple interface for creating deep learning models while handling many of the lower-level details involved in model development.
Keras is commonly used for tasks such as image classification, natural language processing, time-series prediction, and other neural network applications. It can run on top of machine learning backends such as TensorFlow and provides ready-to-use layers, optimisers, loss functions, and training tools.
Layers are the basic building blocks of a Keras neural network. Each layer processes input data and passes the resulting output to the next layer.
Keras provides different types of layers, including dense layers, convolutional layers, recurrent layers, and dropout layers, allowing models to be designed according to the requirements of different tasks.
A model defines how different layers are connected to process input data and produce predictions. Keras provides model-building approaches such as Sequential for creating a straightforward stack of layers.
More complex architectures can be created using the Functional API, which allows multiple inputs, outputs, and connections between layers.
Activation functions determine how the output of a neural network layer is transformed. Common activation functions in Keras include ReLU, sigmoid, and softmax.
They help neural networks learn complex relationships in data and are selected based on the requirements of the model and task.
Keras provides methods for configuring and training neural network models. The compile() method is used to specify the optimiser, loss function, and evaluation metrics, while fit() trains the model using the provided data.
After training, evaluate() can be used to measure model performance and predict() can generate predictions for new data.
compile(), fit(), and evaluate() for configuring, training, and evaluating neural network models. This makes common training workflows easier to implement.Keras is commonly used to develop deep learning models for tasks such as image classification, text processing, speech recognition, and prediction. Its high-level interface makes it easier to create neural networks without manually implementing every part of the training process.
Keras can work with NumPy and pandas for data preparation and can use TensorFlow as its backend for numerical operations and model training.
The following example demonstrates how Keras can be used to build and train a simple neural network for classification:
import tensorflow as tf
X = [[20], [25], [30], [35], [40], [45]]
y = [0, 0, 0, 1, 1, 1]
model = tf.keras.Sequential([
tf.keras.layers.Dense(8, activation="relu"),
tf.keras.layers.Dense(1, activation="sigmoid")
])
model.compile(
optimizer="adam",
loss="binary_crossentropy",
metrics=["accuracy"]
)
model.fit(X, y, epochs=20, verbose=0)
predictions = model.predict([[32], [42]])
print(predictions)Here, Sequential creates a simple neural network by stacking two layers. The first Dense layer uses ReLU to process the input, while the second uses sigmoid to produce the classification output. The compile() method configures the training process, and fit() trains the model using the provided data.
After training, predict() is used to generate outputs for new input values. This demonstrates the basic Keras workflow of building a model, configuring it, training it, and generating predictions.
Keras provides a simple and flexible way to build, train, and evaluate neural networks. Its layers, models, activation functions, and built-in training methods make it useful for developing deep learning applications across tasks such as classification, image processing, and natural language processing.

NLTK (Natural Language Toolkit) is a Python library designed for processing and analysing human language data. It provides tools for common natural language processing (NLP) tasks such as tokenisation, stemming, tagging, parsing, and text classification.
NLTK is commonly used to prepare and analyse text before it is passed to machine learning or NLP models. It also includes text datasets, lexical resources, and utilities that can help developers experiment with and understand different NLP techniques.
Tokenisation breaks text into smaller units such as words or sentences. NLTK provides tools for separating a piece of text into individual tokens that can then be analysed or processed.
For example, a sentence can be divided into individual words, making it easier to perform tasks such as text analysis, frequency counting, or further preprocessing.
Stemming reduces words to a simpler root-like form by removing common word endings. For example, words such as “playing,” “played,” and “plays” may be reduced to a similar stem.
This can help reduce variations of the same word during text processing, although the resulting stem may not always be a complete dictionary word.
Part-of-speech (POS) tagging identifies the grammatical role of words in a sentence, such as noun, verb, adjective, or adverb.
NLTK can assign these tags to tokens, providing information that can be useful for analysing the structure and meaning of text.
NLTK provides tools and resources for building basic text classification systems. Text classification involves assigning text to predefined categories based on its content.
For example, text can be classified into categories such as positive or negative sentiment, different topics, or other predefined groups.
NLTK is commonly used for text preprocessing and linguistic analysis in NLP workflows. It can help clean and transform text through tasks such as tokenisation, stemming, stop-word removal, and part-of-speech tagging before the data is used for machine learning.
It can also work alongside libraries such as NumPy and Scikit-learn. NLTK can handle language-focused preprocessing, while Scikit-learn can be used to convert text into numerical features, train machine learning models, and evaluate their performance.
The following example demonstrates how NLTK can be used to tokenize a sentence and identify its individual words:
import nltk
from nltk.tokenize import word_tokenize
nltk.download("punkt")
text = "Machine learning helps computers learn from data."
tokens = word_tokenize(text)
print(tokens)Here, word_tokenize() divides the sentence into individual words and punctuation marks. The resulting tokens can then be used for further NLP tasks such as text cleaning, feature extraction, or classification.
This demonstrates a basic NLTK workflow of taking raw text, breaking it into tokens, and preparing it for further language processing.
NLTK provides a collection of tools for processing and analysing human language in Python. Its tokenisation, stemming, POS tagging, and text-processing capabilities make it useful for preparing and analysing text in NLP workflows. It can also be combined with machine learning libraries such as Scikit-learn to build text-based applications.

Hugging Face Transformers is a Python library that provides access to pretrained models for natural language processing, computer vision, audio, and multimodal machine learning tasks. It includes models that can be used for tasks such as text classification, text generation, translation, summarisation, question answering, image classification, and speech processing.
The library allows developers to use pretrained models and adapt them to specific tasks instead of building every model from scratch. It also provides tools for loading models, processing input data, fine-tuning models, and generating predictions.
Pretrained models are machine learning models that have already been trained on large datasets. Hugging Face provides access to many pretrained models that can be used for different tasks and types of data.
Developers can use these models directly for inference or further train them on task-specific datasets.
Tokenisation converts text into smaller units that a model can process. A tokenizer can divide text into tokens and convert those tokens into numerical representations that can be passed to a transformer model.
Different models may use different tokenisation methods, so the appropriate tokenizer is generally loaded along with the model.
Transformers are neural network architectures designed to process sequences of data and identify relationships between different parts of the input. They use mechanisms such as attention to determine which parts of the input are important when generating or understanding outputs.
Transformer-based models are widely used for NLP tasks such as language understanding, translation, summarisation, and text generation.
Hugging Face provides pipeline() as a simple interface for performing common machine learning tasks. It can automatically handle steps such as preprocessing input, running the model, and processing the output.
For example, a sentiment-analysis pipeline can take a sentence as input and return the predicted sentiment and confidence score.
Hugging Face Transformers is commonly used for NLP and other AI tasks that require pretrained models. It can be used for sentiment analysis, text classification, summarisation, question answering, translation, text generation, and more.
The library can also work alongside frameworks such as PyTorch and TensorFlow. Developers can use pretrained models for inference or fine-tune them using their own datasets for more specialised applications.
The following example demonstrates how Hugging Face Transformers can be used to perform sentiment analysis using a pretrained model:
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
text = "The machine learning model performed very well."
result = classifier(text)
print(result)Here, pipeline() creates a sentiment-analysis pipeline using a pretrained model. The text is passed to the classifier, which processes it and returns a predicted sentiment along with a confidence score.
This demonstrates the basic Hugging Face workflow of loading a pretrained model, providing input text, and generating a prediction.
Hugging Face Transformers provides access to pretrained transformer models and tools for building AI applications. Its support for tokenisation, pretrained models, pipelines, and model fine-tuning makes it useful for tasks such as text classification, translation, summarisation, and text generation.

LangChain is a framework for developing applications that use large language models (LLMs). It provides components for connecting language models with external data, tools, APIs, databases, and application workflows.
LangChain can be used to build applications such as chatbots, question-answering systems, document-based assistants, and AI workflows. It provides reusable components for handling prompts, retrieving information, managing conversation context, and connecting different parts of an LLM application.
LangChain provides interfaces for working with language models and chat models from different providers. These models can process user input and generate natural language responses.
Using a common interface makes it easier to connect language models to other components of an application and change models when required.
Prompt templates provide a structured way to create prompts for language models. Instead of writing a complete prompt every time, developers can define a template with variables that can be filled with different inputs.
This makes prompts easier to reuse and manage across different parts of an application.
Chains connect multiple steps together to create a specific workflow. For example, a chain can take a user's question, retrieve relevant information, pass that information to a language model, and generate a response.
This allows individual components to work together as part of a larger LLM application.
Retrieval allows an application to find relevant information from external sources before sending it to a language model. LangChain provides components for working with document loaders, text splitters, embeddings, and vector stores.
LangChain is commonly used to develop applications around LLMs rather than to train traditional machine learning models from scratch. It can connect language models with external information, tools, APIs, and databases to create more capable AI applications.
It can also work with model providers and libraries such as OpenAI, Hugging Face, and vector databases, allowing developers to combine different components within a single application workflow.
The following example demonstrates how LangChain can be used to create a simple prompt and send it to a language model:
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_template(
"Explain {topic} in simple terms."
)
messages = prompt.invoke({"topic": "machine learning"})
print(messages)Here, ChatPromptTemplate creates a reusable prompt containing a variable called topic. The invoke() method fills the variable with the provided value and creates the resulting message that can be passed to a chat model.
This demonstrates a basic LangChain workflow of creating a reusable prompt, providing input, and preparing it for a language model.
LangChain provides components for building applications around large language models. Its support for prompt templates, chains, retrieval, and integrations makes it useful for developing chatbots, question-answering systems, document assistants, and other LLM-based applications.

Pandas is a Python library used for working with structured and tabular data. It provides data structures such as DataFrame and Series that make it easier to load, organise, clean, transform, and analyse datasets.
Pandas is widely used in machine learning workflows for preparing data before it is passed to a model. It can handle tasks such as filtering rows, selecting columns, managing missing values, combining datasets, and performing basic data analysis.
A DataFrame is Pandas' main data structure for working with tabular data. It organises data into rows and columns, similar to a spreadsheet or database table.
DataFrames can be used to select specific columns, filter records, modify values, and perform calculations on datasets.
A Series is a one-dimensional Pandas data structure that stores a sequence of values. Each Series can have an associated index, making it useful for representing individual columns or labelled data.
Series can also be used for filtering, calculations, and other data manipulation tasks.
Pandas provides functions for identifying and handling common data-quality issues. These include missing values, duplicate records, incorrect data types, and unwanted values.
Cleaning data before model training helps ensure that the dataset is in a suitable format for further analysis or machine learning.
Pandas provides tools for filtering, sorting, grouping, merging, and reshaping data. These operations make it easier to transform raw datasets into a format that can be analysed or used for machine learning.
For example, rows can be filtered based on conditions, multiple datasets can be combined using merge(), and data can be summarised using groupby().
DataFrame structure for storing and working with tabular data in rows and columns. It makes datasets easier to inspect, organise, filter, and manipulate during data analysis.Pandas is commonly used during the data preparation stage of a machine learning workflow. It can load datasets from sources such as CSV files, Excel files, and databases, and then provide tools for cleaning and transforming the data.
Once the data has been prepared, it can be converted into formats that work with libraries such as Scikit-learn, XGBoost, LightGBM, and other machine learning frameworks.
The following example demonstrates how Pandas can be used to create a dataset, filter its values, and calculate an average:
import pandas as pd
data = {
"Age": [20, 25, 30, 35],
"Score": [75, 82, 90, 68]
}
df = pd.DataFrame(data)
filtered_data = df[df["Score"] >= 80]
average_score = filtered_data["Score"].mean()
print(filtered_data)
print(average_score)Here, DataFrame creates a table from the provided data. The filtering condition selects rows where the Score is 80 or higher, while mean() calculates the average score of the filtered values.
This demonstrates a basic Pandas workflow of creating, filtering, and analysing structured data.
Pandas provides practical tools for organising, cleaning, transforming, and analysing structured data in Python. Its DataFrame and Series structures make it useful for preparing datasets before they are passed to machine learning libraries such as Scikit-learn, XGBoost, and LightGBM.

Polars is a DataFrame library designed for fast data processing and analysis. Written in Rust with a Python API, it supports operations such as filtering, sorting, grouping, joining, and transforming structured datasets.
Polars is commonly used when working with large datasets that require efficient data manipulation. It uses a columnar data format and supports parallel processing and lazy execution, which can help optimise data-processing workflows.
A DataFrame is Polars' primary structure for storing and working with tabular data. It organises data into columns and rows and provides operations for filtering, selecting, transforming, and analysing datasets.
Polars DataFrames can handle numerical, categorical, string, and other data types commonly found in structured datasets.
Lazy execution allows Polars to build a query plan before actually processing the data. Instead of immediately executing every operation, Polars can analyse the complete workflow and optimise how the operations should be performed.
This can reduce unnecessary processing and improve efficiency when working with larger datasets.
Expressions are used to describe data transformations in Polars. They allow operations such as selecting columns, filtering rows, creating new columns, and performing calculations to be written in a structured way.
Expressions can also be optimised as part of Polars' query execution process.
Polars is designed to take advantage of multiple CPU cores when performing data-processing operations. This allows independent operations to run in parallel, which can improve processing speed for suitable workloads.
Polars can be used during the data preparation stage of a machine learning workflow. It can load, clean, filter, transform, join, and analyse structured datasets before they are passed to a machine learning model.
It can also be used alongside libraries such as NumPy, Scikit-learn, XGBoost, and LightGBM. Once data preparation is complete, the processed data can be converted into formats supported by the selected machine learning library.
The following example demonstrates how Polars can be used to create a dataset, filter its values, and calculate an average:
import polars as pl
data = pl.DataFrame({
"Age": [20, 25, 30, 35],
"Score": [75, 82, 90, 68]
})
filtered_data = data.filter(
pl.col("Score") >= 80
)
average_score = filtered_data["Score"].mean()
print(filtered_data)
print(average_score)Here, DataFrame creates a table from the provided data. The filter() operation selects rows where the Score is 80 or higher, while mean() calculates the average of the filtered scores.
This demonstrates a basic Polars workflow of creating, filtering, and analysing structured data.
Polars provides efficient tools for processing and analysing structured datasets in Python. Its DataFrames, expressions, lazy execution, and parallel processing capabilities make it useful for data preparation, particularly when working with larger datasets before machine learning model training.

JAX is a Python library for high-performance numerical computing and machine learning research. It provides NumPy-style operations while adding capabilities such as automatic differentiation, just-in-time compilation, and parallel computation.
JAX is commonly used for developing and training machine learning and deep learning models, particularly when efficient numerical computation is important. It can run computations on CPUs, GPUs, and TPUs, making it useful for large-scale numerical and scientific workloads.
JAX arrays are used to store and manipulate numerical data, similar to NumPy arrays. They support mathematical and array operations while allowing JAX to optimise these computations for different hardware platforms.
JAX arrays form the foundation for many numerical calculations and machine learning operations performed using the library.
JAX provides automatic differentiation through functions such as grad(). It can calculate the derivatives of numerical functions automatically, which is essential for training machine learning models using gradient-based optimisation.
This allows developers to calculate gradients without manually deriving and implementing the required mathematical formulas.
JAX provides just-in-time (JIT) compilation through jit(). It can compile numerical functions so that repeated computations can be executed more efficiently.
JIT compilation is particularly useful when the same numerical operations need to be performed many times during model training or other computational workloads.
JAX provides vmap() for automatically applying a function across batches of data. This makes it easier to perform the same computation on multiple inputs without manually writing loops.
Vectorisation can be useful when processing batches of data during machine learning workflows.
JAX is commonly used for numerical computing, scientific research, and developing machine learning and deep learning models. Its automatic differentiation, compilation, and hardware acceleration capabilities make it useful for computationally intensive workloads.
JAX can also work with neural network and optimisation libraries such as Flax and Optax, allowing developers to build and train more complex machine learning models.
The following example demonstrates how JAX can be used to calculate the gradient of a mathematical function:
import jax
import jax.numpy as jnp
def function(x):
return x ** 2 + 3 * x
gradient = jax.grad(function)
x = 5.0
print(gradient(x))Here, jax.numpy provides NumPy-style numerical operations, while jax.grad() automatically calculates the derivative of the function. For the given input, JAX calculates the gradient without requiring the derivative to be written manually.
This demonstrates a basic JAX workflow of defining a numerical function, applying automatic differentiation, and calculating its gradient.
JAX provides NumPy-style numerical computing with features such as automatic differentiation, JIT compilation, and vectorisation. These capabilities make it useful for high-performance numerical workloads and machine learning research, particularly when models require efficient gradient calculations and hardware acceleration.

Matplotlib and Seaborn are Python libraries used to create charts and visualise data. Matplotlib provides a flexible foundation for creating different types of plots, while Seaborn builds on Matplotlib and offers a simpler interface for creating statistical visualisations.
Both libraries are commonly used during data analysis and machine learning workflows to understand datasets, identify patterns, compare values, and communicate results through visualisations.
Matplotlib is a general-purpose visualization library that provides tools for creating line charts, bar charts, scatter plots, histograms, and other types of visualisations.
It gives developers detailed control over elements such as axes, labels, titles, markers, and figure layouts, making it useful when customised visualisations are required.
Seaborn is a statistical data visualization library built on top of Matplotlib. It provides higher-level functions for creating visualisations from structured datasets and includes built-in themes and statistical plotting features.
Seaborn is useful for exploring relationships, distributions, correlations, and patterns within datasets with relatively little code.
Both libraries can be used to visualise statistical information in datasets. Common examples include distributions, correlations, trends, and comparisons between different groups.
These visualisations can make patterns and relationships easier to identify during exploratory data analysis.
Matplotlib provides extensive control over the appearance and structure of charts. Seaborn also provides styling options while simplifying many common statistical plots.
Developers can customise titles, labels, axes, legends, and other elements to make visualisations easier to interpret.
Matplotlib and Seaborn are commonly used during exploratory data analysis and model evaluation. They can help visualise feature distributions, relationships between variables, correlations, and model results before and after training.
They can also work alongside libraries such as Pandas, NumPy, and Scikit-learn. Pandas and NumPy can prepare numerical data, while Matplotlib and Seaborn can be used to visualise that data and understand patterns before building or evaluating a machine learning model.
The following example demonstrates how Matplotlib and Seaborn can be used to visualise a simple dataset:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.DataFrame({
"Age": [20, 25, 30, 35, 40],
"Score": [65, 72, 80, 85, 90]
})
sns.scatterplot(data=data, x="Age", y="Score")
plt.title("Age vs Score")
plt.xlabel("Age")
plt.ylabel("Score")
plt.show()Here, Pandas creates a DataFrame containing the dataset, while Seaborn's scatterplot() creates a visual relationship between age and score. Matplotlib is then used to add the chart title and axis labels.
This demonstrates how Pandas, Seaborn, and Matplotlib can work together to explore and visualise structured data.
Matplotlib and Seaborn provide useful tools for visualising and understanding data in Python. Their charts and statistical plots can help identify patterns, relationships, and trends during data analysis and machine learning workflows.

OpenCV (Open Source Computer Vision Library) is an open-source library used for image and video processing, computer vision, and visual data analysis. It provides functions for reading, modifying, analysing, and processing images and video.
In machine learning workflows, OpenCV is often used to prepare visual data before it is passed to a machine learning or deep learning model. It can resize images, change colour formats, detect edges, and perform other preprocessing tasks required for computer vision applications.
OpenCV provides functions for basic image operations such as resizing, cropping, rotating, and changing image formats. These operations help prepare images for analysis or model training.
Image filtering techniques can be used to reduce noise, smooth images, or highlight specific visual features. OpenCV provides filters such as Gaussian blur and median filtering for these tasks.
OpenCV includes techniques for detecting edges, corners, and other important features in images. These features can help identify shapes, objects, or patterns in visual data.
OpenCV can read and process video frames from files or cameras. Each frame can be analysed individually for tasks such as object detection, motion tracking, and other computer vision applications.
OpenCV is commonly used during the data preparation and preprocessing stages of computer vision workflows. Images can be resized, converted to grayscale, normalised, or transformed before being provided to machine learning models.
It can also be combined with libraries such as TensorFlow, PyTorch, and Scikit-learn to create computer vision applications for image classification, object detection, facial recognition, and image analysis.
The following example demonstrates how OpenCV can be used to read an image, convert it to grayscale, and resize it.
import cv2
image = cv2.imread("image.jpg")
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
resized_image = cv2.resize(gray_image, (300, 300))
cv2.imwrite("processed_image.jpg", resized_image)This code reads an image using cv2.imread(), converts it from colour to grayscale using cv2.cvtColor(), and resizes it to 300 × 300 pixels using cv2.resize(). The processed image is then saved using cv2.imwrite().
The basic workflow is to load the image, apply the required preprocessing operations, and save or pass the processed data to the next stage of the computer vision pipeline.
OpenCV provides a wide range of tools for processing and analysing images and video. Its image processing, filtering, feature detection, and video processing capabilities make it useful for preparing visual data and developing computer vision applications alongside machine learning and deep learning frameworks.
You do not need to use all 14 Python machine learning libraries in every project. The right combination depends on the type of data you are working with, the machine learning task, and whether the project involves traditional machine learning, deep learning, computer vision, NLP, or generative AI.
The libraries can also be used together. For example, a project may use Pandas for data preparation, Scikit-learn for model training, and XGBoost for gradient boosting. Choosing libraries based on the project's requirements keeps the workflow focused and avoids adding tools that are not needed.
For projects that work mainly with structured or tabular data, a practical starting combination is:
NumPy + Pandas or Polars + Scikit-learn
NumPy provides numerical operations and array handling, while Pandas or Polars can be used to load, clean, transform, and analyse structured datasets. Scikit-learn then provides tools for preprocessing, model training, prediction, and evaluation.
When the project requires gradient-boosted decision trees, XGBoost or LightGBM can be added. Both are useful for classification, regression, and other tasks involving structured data.
For deep learning projects, PyTorch or TensorFlow/Keras can be used to build and train neural networks. The choice between them depends on the project's requirements, existing team knowledge, and preferred development workflow.
For image processing and computer vision tasks, OpenCV can be used alongside these frameworks. It handles operations such as image resizing, filtering, colour conversion, and video processing before the visual data is passed to a machine learning or deep learning model.
JAX can also be considered for research-oriented experimentation and numerical workloads where automatic differentiation, compilation, vectorisation, and accelerator performance are important.
For applications based on large language models, Hugging Face Transformers is useful for accessing pretrained models, tokenising text, running inference, and fine-tuning supported models.
LangChain can be added when an application needs more than direct model interaction. It provides components for workflows involving retrieval, external tools, prompts, multi-step processing, and agent-based applications.
These libraries can also be used together. For example, Hugging Face Transformers can provide the underlying model while LangChain handles parts of the application workflow around it.
For classical NLP tasks and learning the fundamentals of text processing, NLTK remains useful. It provides tools for tokenisation, stemming, part-of-speech tagging, and other traditional NLP operations.
For many modern NLP applications, transformer-based models have become an important approach. Libraries such as Hugging Face Transformers provide access to pretrained transformer models that can be used for tasks such as text classification, summarisation, translation, and text generation.
The earlier sections explain what each library does, but knowing the purpose of a library does not always tell you which one belongs in a particular project. This decision guide connects the individual libraries to common machine learning use cases.
Instead of trying to learn or use every library at once, readers can start with the tools that match their project and add other libraries when a specific requirement calls for them.

Python offers a wide range of libraries that support different stages of the machine learning workflow, from numerical computing and data preparation to model training, deep learning, computer vision, NLP, and generative AI. Libraries such as NumPy, Pandas, Polars, and Scikit-learn provide a foundation for working with data and traditional machine learning, while XGBoost and LightGBM support gradient boosting. PyTorch, TensorFlow, Keras, and JAX are useful for deep learning and numerical experimentation, while OpenCV supports image and video processing.
For NLP and generative AI applications, NLTK, Hugging Face Transformers, and LangChain serve different purposes, ranging from traditional text processing to pretrained models and LLM-based application workflows. The key is not to use every library in a single project, but to choose the tools that match the data, task, and development requirements. Understanding what each library does makes it easier to build a practical and efficient machine learning workflow in Python.