Page
1
(This page has no text content)
Page
2
Graph Machine Learning Second Edition Learn about the latest advancements in graph data to build robust machine learning models Aldo Marzullo Enrico Deusebio Claudio Stamile
Page
3
Graph Machine Learning Second Edition Copyright © 2025 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors nor Packt Publishing or its dealers and distributors will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Portfolio Director: Sunith Shetty Relationship Lead: Sanjana Gupta Project Manager: Shashank Desai Content Engineer: Tiksha Abhimanyu Lad Technical Editor: Gaurav Gavas Copy Editor: Safis Editing Indexer: Pratik Shirodkar Proofreader: Safis Editing and Tiksha Lad Production Designer: Ganesh Bhadwalkar and Salma Patel Growth Lead: Bhavesh Amin First published: May 2021 Second edition: June 2025 Production reference: 2150725 Published by Packt Publishing Ltd. Grosvenor House 11 St Paul’s Square Birmingham B3 1RB, UK. ISBN 978-1-80324-806-6 www.packtpub.com
Page
4
Contributors About the authors Aldo Marzullo received an M.Sc. degree in computer science from the University of Calabria (Cosenza, Italy) in September 2016. During his studies, he developed a solid background in several areas, including algorithm design, graph theory, and machine learning. In January 2020, he received his joint Ph.D. from the University of Calabria and Université Claude Bernard Lyon 1 (Lyon, France), with a thesis titled Deep Learning and Graph Theory for Brain Connectivity Analysis in Multiple Sclerosis. He is currently a postdoctoral researcher and collaborates with several international institutions. For those I hold close, and those I carry quietly with me. Aldo Marzullo Enrico Deusebio is currently working as engineering manager at Canonical, the publisher of Ubuntu, to promote open source technologies in the data and AI space and to make them more accessible to everyone. He has been working with data and distributed computing for over 15 years, both in an academic and industrial context, helping organizations implement data-driven strategies and build AI-powered solutions. He has collaborated and worked with top-tier universities, such as the University of Cambridge, University of Turin, and the Royal Institute of Technology (KTH) in Stockholm, where he obtained a Ph.D. in 2014. He holds a B.Sc. and an M.Sc. degree in aerospace engineering from Politecnico di Torino. To Lili and Pepe, for always reminding me, with your learning process, how wonderful the human brain and life are. Enrico Deusebio
Page
5
Claudio Stamile received an M.Sc. degree in computer science from the University of Calabria (Cosenza, Italy) in September 2013 and, in September 2017, he received his joint Ph.D. from KU Leuven (Leuven, Belgium) and Université Claude Bernard Lyon 1 (Lyon, France). During his career, he developed a solid background in AI, graph theory and machine learning with a focus on the biomedical field. A Enea, che ha dato senso a molti silenzi. To Enea, who gave meaning to many silences. Claudio Stamile
Page
6
About the reviewer Nathan Smith is a principal consultant in the professional services division of Neo4j. As a data scientist, he works with companies to apply graph algorithms for machine learning and analytics. He is an organizer of the Data Science Kansas City Meetup, and he enjoys engaging with the data science community through blog posts in Towards Data Science, Medium, and the Neo4j Developer Blog.
Page
7
(This page has no text content)
Page
8
(This page has no text content)
Page
9
(This page has no text content)
Page
10
(This page has no text content)
Page
11
(This page has no text content)
Page
12
(This page has no text content)
Page
13
(This page has no text content)
Page
14
(This page has no text content)
Page
15
(This page has no text content)
Page
16
(This page has no text content)
Page
17
(This page has no text content)
Page
18
Preface This updated and expanded second edition brings several significant improvements to help you stay ahead in the evolving field of graph machine learning. Compared to the previous version, this edition features refined chapters for improved clarity and flow, new examples utilizing both legacy tools and modern frameworks such as PyTorch and DGL, and entirely new chapters covering cutting-edge topics such as temporal graph machine learning and the integration of large language models (LLMs). Graph Machine Learning provides a powerful toolkit for processing network-structured data and leveraging the relationships between entities for predictive modeling, analytics, and more. You’ll begin with a concise introduction to graph theory, graph machine learning, and neural networks, building a foundational understanding of their principles and applications. As you progress, you’ll dive into the core machine learning models for graph representation learning, exploring their goals, inner workings, and practical implementation across various supervised and unsupervised tasks. You’ll develop an end-to-end machine learning pipeline, from data preprocessing to training and prediction, to fully harness the potential of graph data. Throughout the book, you’ll find real-world scenarios such as social network analysis, natural language processing with graphs, and financial transaction systems. The later chapters take you through the creation of scalable, data-intensive applications for storing, querying, and processing graph data and introduce you to the recent breakthroughs and emerging trends in the domain, some of which are the interaction between graphs and LLMs used in the context of generative AI and retrieval-augmented generation (RAG) systems. By the end of this book, you will have understood the key concepts of graph theory and machine learning algorithms, allowing you to develop impactful graph-based machine learning solutions.
Page
19
Prefacexviii Who this book is for This book is for data analysts, graph developers, graph analysts, and graph professionals who want to leverage the information embedded in the connections and relations between data points, unravel hidden structures, and exploit topological information to boost their analysis and models’ performance. The book will also be useful for data scientists and machine learning developers who want to build machine learning-driven graph databases. What this book covers Chapter 1, Getting Started with Graphs, introduces the basic concepts of graph theory using the NetworkX Python library. Chapter 2, Graph Machine Learning, introduces the main concepts of graph machine learning and graph embedding techniques. Chapter 3, Neural Networks and Graphs, introduces Graph Neural Networks (GNNs) and the leading libraries for graph-based deep learning. Chapter 4, Unsupervised Graph Learning, covers recent unsupervised graph embedding methods. Chapter 5, Supervised Graph Learning, covers recent supervised graph embedding methods. Chapter 6, Solving Common Graph-Based Machine Learning Problems, introduces the most common machine learning tasks on graphs. Chapter 7, Social Network Graphs, shows an application of machine learning algorithms on social network data. Chapter 8, Text Analytics and Natural Language Processing Using Graphs, shows an application of machine learning algorithms on a natural language processing task. Chapter 9, Graphs Analysis for Credit Card Transactions, shows an application of machine learning algorithms in credit card fraud detection. Chapter 10, Building a Data-Driven Graph-Powered Application, introduces some technologies and techniques useful to deal with large graphs. Chapter 11, Temporal Graph Machine Learning, focuses on techniques to model and learn from dynamic, time-evolving graph data. Chapter 12, GraphML and LLMs, explores how graph structures can enhance LLMs and how LLMs can be used for graph-based tasks.
Page
20
Preface xix Chapter 13, Novel Trends on Graphs, introduces some novel trends (algorithms and applications) of graph machine learning. To get the most out of this book We recommend that you use Docker to have a reproducible environment and stable dependency sets. The provided Docker images – one for each chapter – ship with a Jupyter installation and a Python kernel with the dependencies pre-installed, which you can use to run all the examples. For some chapters, Neo4j, JanusGraph, and Gephi are also needed. Software/hardware covered in the book OS requirements Python Windows, macOS, and Linux (any) Neo4j Windows, macOS, and Linux (any) Gephi Windows, macOS, and Linux (any) Docker Windows, macOS, and Linux (any) A beginner-level understanding of graph databases and graph data is required. Intermediate-level working knowledge of Python programming and machine learning is also expected to make the most of this book. The authors acknowledge the use of cutting-edge AI, such as ChatGPT, with the sole aim of enhancing the language and clarity within the book, thereby ensuring a smooth reading experience for readers. It’s important to note that the content itself has been crafted by the authors and edited by a professional publishing team. Download the example code files The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/ Graph-Machine-Learning. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out! Conventions used There are a number of text conventions used throughout this book. CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and X/Twitter handles. For example: “For this exercise, we will be using a GraphSAGE encoder with three layers of 32, 32, and 16 dimensions, respectively.”