Creating a Recommender System (Part I)


This two-article series explains how to design and implement a hybrid recommender system that works just like the ones used by Amazon or Ebay.

Introduction

Let’s start with a short definition from Wikipedia:

Recommender systems or recommendation systems (sometimes replacing “system” with a synonym such as platform or engine) are a subclass of information filtering system that seek to predict the ‘rating’ or ‘preference’ that a user would give to an item.

The following diagram is a basic illustration:

Recommender System diagram
Recommender System diagram

A recommender system analyses input data which contains information on different products and their user ratings. After reading and processing the data, the system  creates a model that can be used to predict ratings for a particular product or user.

Approaches

In the recommender system world, there are three types of approaches to filter products:

  1. Collaborative filtering: this approach is based on collecting and analysing a large amount of information on users’ behaviours, activities or preferences and predicting what they  like based on their similarity to other users.
  2. Content-based filtering: this approach is based on descriptions of user-preferences and items they have looked at or purchased in the past.
  3. Hybrid recommender systems: The hybrid approach combines collaborative filtering and content-based filtering.

In this article, we will use all three approaches.

Architecture

We have selected the Stratio Platform as the base-solution because it eases the task of developing applications based on Spark and many other Big Data solutions.

Architecture
Architecture

Our recommender system is divided into three main modules:

  1. Dataset Loader: this submodule will download the dataset from the Internet, process and store it in our two main data stores (MongoDB and ElasticSearch).
  2. Recommender Trainer: all the ratings stored in the DB by the previous module will be used to create a Collaborative Filtering model and pre-calculate recommendations for all users and products which will then in turn be stored in MongoDB.
  3. Recommender Server: using a small REST server we will send recommendation queries to MongoDB and ElasticSearch.

Dependencies

This is the list of libraries used by this system:

Dataset Loader

This submodule is responsible for downloading, reading, transforming and saving the dataset into our two data stores (MongoDB and ElasticSearch).

By way of example, we have selected a Dataset consisting of a million Amazon reviews for more than 20,000 products in JSON format: AmazonReviews.

Here is a brief description of the dataset:

This data set contains Amazon product reviews under six categories: camera, mobile phone, TV, laptop, tablet and video surveillance systems.

Each product contains the attributes of: product ID (unique), name, product features, listing price and image URL.

Each review contains the attributes of: review ID (unique), author, title, content, overall rating, date.

Once we have downloaded the dataset to the disk, we have to read the JSON files using Spark SQL which is a very simple task:

It is then necessary to organise all the rows of our Product/Review model:

And to save the Product/Review tuples in the MongoDB:

Finally, all the Products should be saved in ElasticSearch:

Conclusions

The first part of this series gives an overview of what a recommender system is, what its main parts are and some basic algorithms which are frequently used in these kinds of systems. We have also implemented some functions using Spark SQL to read JSON files and to organise the data in MongoDB and ElasticSearch using Spark connectors.

We have not yet coded anything related to recommendation algorithms as this will be covered in the second part of the series along with:

  • Generating our Collaborative Filtering model.
  • Pre-calculating product / user recommendations.
  • Launching a small REST server to interact with the recommender.
  • Querying the data store to retrieve content-based recommendations.
  • Mixing the different types of recommendations to create a hybrid recommender.

Coming soon.

Leave a comment

Please be polite. We appreciate that. Your email address will not be published and required fields are marked