Graphs Everywhere! An Introduction to Graph ML
Tags: Data Science, Machine Learning, Data Structures, Graph

Graphs Everywhere! An Introduction to Graph ML RappiBank Follow Sep 1 · 7 min read

By Luisa F. Roa, Ana M. Quintero Ossa, Jaime D. Acevedo-Viloria

What is a Graph? — They are EVERYWHERE!

Graphs are structures made up of nodes and edges; the nodes represent entities, and the edges represent interactions/connections between a pair of nodes. Many systems can be represented as graphs since only interactions between entities are required, from social networks to drug discovery, most types of problems can be modeled as graphs. For example, the theory of six degrees of separation uses graphs and the concept of “friend of a friend” to prove that we are only 6 people away from everyone in the world. Amazing, isn’t it?

Six-degree separation

In addition to the fact that this type of data is abundant (although it is often not seen), graphs have been shown to have an added value when studying different types of problems. In fact, in recent years, the use of graphs in machine learning has become so popular that the increase in papers related to graphs has been exponential in the four major AI conferences, as seen in Figure 1. Hence a new branch of machine learning commonly known as Graph ML has emerged, this focuses on how to obtain features based on graphs and the development of algorithms that consider the structure of a graph.

Fig 1

But… Why Graphs?

Why graphs have caused such a boom in the field of AI is due to two main reasons. First, the development of computational resources (GPUs) that allow processing these types of graphs, and second, the knowledge that these structures capture shows that connections are as important as the data itself and outperform traditional ML tabular data and models.

Let’s focus on the advantages that graphs offer:

Provides context: Graphs connect and structure knowledge of a system leveraged by connections and interactions.

Graphs connect and structure knowledge of a system leveraged by connections and interactions. Shows temporal evolution: Graphs are capable of capturing the evolutions of your system without having to create temporary variables or have complex definitions.

Graphs are capable of capturing the evolutions of your system without having to create temporary variables or have complex definitions. Contains business/problem logic: Graphs based on different types of interactions are capable of generating a data structure that intrinsically captures the logic behind a problem or business.

Graphs based on different types of interactions are capable of generating a data structure that intrinsically captures the logic behind a problem or business. Easy interpretation: Since we have an intuition of how graphs work in our daily life, they are easy to explain and visually show results derived from them.

Now: Machine Learning with Graphs

As explained before graphs are able to capture new information from a particular problem; therefore, they are also able to build new robust ML tasks to predict over a particular node, the connection between a pair of nodes, or even over a whole graph. Taking this into account, the first thing to do is to define what information we are expecting to extract from the graph and what would be an appropriate structure that captures this information.

For example, if we want our system to predict if someone X would be interested in taking a job for a company Y (such as LinkedIn) a graph that connects people and companies by the first letter of their name would not be useful. On the contrary, if the connection would be related to their interest in a particular industry and the company’s industry, the output would be pretty great.

After realizing the structure, it will lead us to identify the primary entities, and the relation that joins them together; which will be the nodes (N) and edges (E); in fact, in many cases, we can think of more than one type of nodes and more than one type of relations. This is the notion of homogeneous (one type of nodes and edges) and heterogeneous (more than one type of nodes and edges) graphs, which is very useful and can give a better understanding of the system.

Finally, we can add relevant information about the entities we choose as well as the edges, usually tabular data in traditional ML tasks. For example, labels/categories for nodes, numeric features for nodes, weights in edges, and many others that contribute to extract better information

What can ML do with graphs?

We can gather all algorithms and their objectives in 3 general ML tasks:

Classification (nodes): As in traditional ML, classification is a big issue that should be solved. In this case, for graphs, we can classify the label of a node given its neighbors — What is my favorite sport if all my friends have soccer as their favorite sport? Probably soccer too. Link prediction: In this case, the objective is to determine if there might be a connection between a pair of entities given the structure between them — Would you know the best friend of your best friend eventually? or, would you buy fancy shoes if you already bought a fancy dress? Big companies as Facebook, Amazon, LinkedIn, use this concept to suggest relationships Graph classification: As complex as it might sound, it attempts to identify if the whole can be classified as a previously seen graph given the structure — this is commonly used in molecules detection in chemistry

How has Rappi Bank taken advantage of Graph ML?

Graphs are useful for the detection of patterns in the way a group of users interacts with the rest. These are some examples:

Fraud Detection

Let’s say we create a graph where we join users in a graph where they are connected to the devices where they have logged in to the app, and the credit cards that are registered in the app. Normally, a user wouldn’t have much of these interactions, maybe just having the interactions between direct family members and so. An example would be the next graph, which can probably represent a couple with a child, where the child has used the credit cards of both his parents.

On the other hand, fraudsters that are attempting to violate another person’s account or credit card would create suspect patterns in the graph. In the case of attempting to access another person’s account, we would see an agglomeration of accounts logged in the same device. In the case of a fraudster attempting to access another person’s credit card through the app, we would see many different credit cards registered to a single user. We can see in the next example graph, how the previous healthy graph could be contaminated by a couple of fraudulent users.

We can leverage both of these interactions to detect fraudulent users live with a graph-enhanced model.

Credit Score Estimation

Graphs can also help us find more complex interactions for the detection of communities or the finding of strong relationships. This is highly valuable in a credit risk prediction task, where not all the users possess a credit history.

Using multiple interactions we can assume an un-banked user would behave similarly to a strongly connected banked user. Let’s say if they share the banked user’s credit card, their favorite place to order deliveries, and the same IP, we could be looking at a couple where the Credit Risk could be quite similar for both of them. We can even expand this idea and search for strongly connected small communities. This, with the idea of finding families, where children over 18 years old could be targets for a protected credit card given the Parents Credit History.

Let’s take the previous healthy graph and further add GeoHash connections, here, we could assume that any un-banked user of the subgraph would have a similar Credit Risk to the others in the graph.

Further Knowledge

As you can see, graphs are an amazing area that has the potential to boost the Machine Learning and Artificial Intelligence models in all data-driven companies. Stay tuned for our following post where we are going to discuss ML tasks with graphs, algorithms, and some case studies