Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Neo4j 3.x - Second Edition

You're reading from  Learning Neo4j 3.x - Second Edition

Product type Book
Published in Oct 2017
Publisher Packt
ISBN-13 9781786466143
Pages 316 pages
Edition 2nd Edition
Languages
Concepts
Author (1):
Jerome Baton Jerome Baton
Profile icon Jerome Baton

Table of Contents (24) Chapters

Title Page
Credits
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Graph Theory and Databases Getting Started with Neo4j Modeling Data for Neo4j Getting Started with Cypher Awesome Procedures on Cypher - APOC Extending Cypher Query Performance Tuning Importing Data into Neo4j Going Spatial Security Visualizations for Neo4j Data Refactoring with Neo4j Clustering Use Case Example - Recommendations Use Case Example - Impact Analysis and Simulation Tips and Tricks

Chapter 14. Use Case Example - Recommendations

In this chapter, we will look at how we can use the Neo4j graph database for a very specific use case, in which it shines. All the discussions so far have led us to this discussion, where we really want to zoom in on how one would practically use a database such as Neo4j for a very specific use case.

We will look at the following topics in this chapter:

  • Modeling product relationships as a graph
  • Using relationships to suggest recommendations
  • Using relationships to detect fraud

Recommender systems dissected


We will take a look at so called recommender systems in this chapter. Such systems, broadly speaking, consist of two elementary parts:

  • A pattern discovery system: This is the system that somehow figures out what would be a useful recommendation for a particular target group. This discovery can be done in many different ways, but in general, we see three ways to do so:
    • A business expert who thoroughly understands the domain of the graph database application will use this understanding to determine useful recommendations. For example, the supervisor of a do-it-yourself retail outlet would understand a particular pattern. Suppose that if someone came in to buy multiple pots of paint, they would probably also benefit from getting a gentle recommendation for a promotion of high-end brushes. The store has that promotion going on right then, so the recommendation would be very timely. This process would be a discovery process where the pattern that the business expert...

Using a graph model for recommendations


We will be using a very specific data model for our recommender system. In total, we have the following:

  • Ten products
  • Three product brands
  • Fifty relationships between existing person nodes and the mentioned products, highlighting that these persons bought these products

These are the products and brands that we added:

Adding products and brands to the dataset

The following diagram shows the resulting model:

 Our meta model

In Neo4j, this model will look something like the following:

A view on our dataset

A dataset like this one, while of course a broad simplification, offers us some interesting possibilities for a recommender system. Let's take a look at some queries that could really match this use case and would allow us to either visually or in real time exploit the data in this dataset in a product recommendation application.

Specific query examples for recommendations


In this example dataset, we will explore a couple of interesting queries that would allow us--with the information that is available to us--to construct interesting recommendations for our hypothetical users. We will do so along different axes:

  • Product purchases
  • Brand loyalty
  • Social and/or family ties

Let's start with the first and work our way through.

Recommendations based on product purchases

Let's build this thing from the ground up. The first query that we want to write is based on past purchasing behavior. We would like to find people that already share a couple of products that they have purchased in the past, but that also explicitly do not share a number of other products. In our data model, this Cypher query would go something as follows:

match (p1:Person)-[:BOUGHT]->(prod1:Product)<-[:BOUGHT]-(p2:Person)-[:BOUGHT]->(prod2:Product) 
where not(p1-[:BOUGHT]->prod2) 
return p1.name as FirstPerson, p2.name as SecondPerson, prod1.name...

Business variations on recommendations


The entire principle of a recommender system, as we described before, can be generalized into a different kind of system that has many other business applications. Some people would call it a rules engine, which does some kind of sophisticated if-this-then-that matching and figures out what action to take at the other end of the decision tree. Other people may call it a pattern-matching system, which could be applied to any kind of pattern and tied to any kind of action. Most likely, graph databases such as Neo4j hold some characteristics of all of the above and provide you with an interesting infrastructural optimization that could serve well.

Before wrapping up this chapter, we would like to highlight some use cases that are extremely related to the recommender system use case. Let's go through some well-known sweet spot applications that essentially use the same principles underneath.

Fraud detection systems


We have seen a number of customers that are using graph database management systems such as Neo4j for fraud detection systems. The principle is quite simple: in many cases, the fraud of a particular nature is not defined by one transaction only, but by a chain of transactions that have their specific characteristics and that need to be compared to one another to see if they really do constitute a case of fraud.

In the following example, we are just looking at a suspect case of credit card fraud:

A suspect case of credit card fraud

A particular user always uses his credit card for transactions at a particular store. Another user uses his credit card for similar transactions at a different store. All of a sudden, there is this new transaction in the middle, which uses the credit card (let's say for a similar kind of transaction) in the other store. This kind of pattern may become flagged as a suspect pattern in some fraud detection systems.

The system would not necessarily...

Access control systems


Another example of a similar system that uses the principles of a recommender system--defining a pattern and then matching for its occurrences--for a different use case is an access control system:

An access graph

Social networking systems


Obviously, there are a lot of recommender systems that will be very specific to a domain. In the past couple of years, with the massive rise of social networking tools and social apps all around us, the interest in social recommender systems has grown massively. Essentially, we are looking to make useful new connections between people that are effectively part of the same social circle, but may not have realized it yet.

Looking at the following sample network should clarify this immediately:

A social networking graph

In the preceding simple network, there is a very high likelihood that we can close some friendship loops very easily, by suggesting connections between new links between people. Very often, we will be using the graph theory principle of triadic closures, meaning that we will be closing the missing links of the triangles in the structure of our network.

So let's explore this social networking use case some more in the following chapter with a very specific...

Questions and answers


Q1: In order to build a recommendation system, I need an artificial intelligence engine that will take a look at my data and discover the recommendation patterns for me automatically.

  1. True
  2. False

Answer: False. Recommender systems can be based on business knowledge that your staff already has, a visual pattern you discover while browsing the data, or some kind of algorithmic machine learning process. All three can provide meaningful recommendation patterns for your business applications.

Q2: Recommender systems can only be applied in an Amazon-style retail environment, where you have a massive amount of data to base your recommendations on.

  1. True
  2. False

Answer: False. Recommendations are useful in many different business domains, not just retail product recommendations. Fraud detection systems (I recommend that you put this person in jail.) are just one example of a business application that has nothing to do with retail but that will use the same pattern matching capabilities...

Summary


In this chapter, we gave you an overview of how graph databases such as Neo4j could be used in a recommender system. There are a lot of things that we did not discuss, which are out of the scope of this book, but that would probably be part of a true enterprise-class recommender system. Nevertheless, we hope to have illustrated that the querying power of Neo4j will open up a wealth of new opportunities for real-time recommender systems, where recommendations would no longer need to be pre-calculated but rather leveraged in near real time.

The next chapter will use an example of a use case to teach you about analyzing the impact change has on a process or system. It will also teach you how to analyze impact through graphs.

 

 

 

lock icon The rest of the chapter is locked
You have been reading a chapter from
Learning Neo4j 3.x - Second Edition
Published in: Oct 2017 Publisher: Packt ISBN-13: 9781786466143
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}