Reader small image

You're reading from  R Machine Learning Projects

Product typeBook
Published inJan 2019
Reading LevelExpert
PublisherPackt
ISBN-139781789807943
Edition1st Edition
Languages
Right arrow
Author (1)
Dr. Sunil Kumar Chinnamgari
Dr. Sunil Kumar Chinnamgari
author image
Dr. Sunil Kumar Chinnamgari

Dr. Sunil Kumar Chinnamgari has a Ph.D. in computer science and specializes in machine learning and natural language processing. He is an AI researcher with more than 14 years of industry experience. Currently, he works in the capacity of lead data scientist with a US financial giant. He has published several research papers in Scopus and IEEE journals and is a frequent speaker at various meetups. He is an avid coder and has won multiple hackathons. In his spare time, Sunil likes to teach, travel, and spend time with family.
Read more about Dr. Sunil Kumar Chinnamgari

Right arrow

Implementing a Jokes Recommendation Engine

I am sure this is something you have experienced as well: while shopping for a cellphone on Amazon, you are also shown some product recommendations of mobile accessories, such as screen guards and phone cases. Not very surprisingly, most of us end up buying one or more of these recommendations! The primary purpose of a recommendation engine in an e-commerce site is to lure buyers into purchasing more from vendors. Of course, this is no different from a salesperson trying to up-sell or cross-sell to customers in a physical store.

You may recollect the Customers Who Bought This Item Also Bought This heading on Amazon (or any e-commerce site) where recommendations are shown. The aim of these recommendations is to get you to buy not just one product but a product combo, therefore pushing the sales revenues in an upward direction. Recommendations...

Fundamental aspects of recommendation engines

While the basic intent of showing recommendations is to push sales, they actually serve just beyond the better sales concept. Highly personalized content is something recommendation engines are able to deliver. This essentially means that recommendation engines on a retail platform such as Amazon are able to offer the right content to the right customer at the right time through the right channel. It makes sense to provide personalized content; after all, there is no point in showing an irrelevant product to a customer. Also, with the lower attention spans of customers, businesses want to be able to maximize their selling opportunities by showing the right products and encouraging them to buy the right products. At a very high level, personalized content recommendation is achieved in AI in several ways:

  • Mapping similar products that...

Getting started

To get started, you will have to download the supporting files from the GitHub link.

Understanding the Jokes recommendation problem and the dataset

Dr. Ken Goldberg and his colleagues, Theresa Roeder, Dhruv Gupta, and Chris Perkins, introduced a dataset to the world through their paper Eigentaste: A Constant Time Collaborative Filtering Algorithm, which is pretty popular in the recommender-systems domain. The dataset is named the Jester's jokes dataset. To create it, a number of users are presented with several jokes and they are asked to rate them. The ratings provided by the users for the various jokes formed the dataset. The data in this dataset is collected between April 1999 and May 2003. The following are the attributes of the dataset:

  • Over 11,000,000 ratings of 150 jokes from 79,681 users
  • Each row is a user (Row 1 = User #1)
  • Each column is a joke (Column 1 = Joke #1)
  • Ratings are given as real values from -10.00 to +10.00; -10 being the lowest possible...

Building a recommendation system with an item-based collaborative filtering technique

The recommenderlab package of R offers the item-based collaborative filtering (ITCF) option to build a recommendation system. This is a very straightforward approach that just needs us to call the function and supply it with the necessary parameters. The parameters, in general, will have a lot of influence on the performance of the model; therefore, testing each parameter combination is the key to obtaining the best model for recommendations. The following are the parameters that can be passed to the Recommender function:

  • Data normalization: Normalizing the ratings matrix is a key step in preparing the data for the recommendation engine. The process of normalization processes the ratings in the matrix by removing the rating bias. The possible values for this parameter are NULL, Center, and Z...

Building a recommendation system with a user-based collaborative filtering technique

The Jokes recommendation system we built earlier, with item-based filtering, uses the powerful recommenderlab library available in R. In this implementation of the user-based collaborative filtering (UBCF) approach, we make use of the same library.

The following diagram shows the working principle of UBCF:

Example depicting working principle of user based collaborative filter

To understand the concept better, let's discuss the preceding diagram in detail. Let's assume that there are three users: X,Y, and Z. In UBCF, users X and Z are very similar as both of them like strawberries and watermelons. User X also likes grapes and oranges. So a user-based collaborative filter recommends grapes and oranges to user Z. The idea is that similar people tend to like similar things.

The primary...

Building a recommendation system based on an association-rule mining technique

Association-rule mining, or market-basket analysis, is a very popular data mining technique used in the retail industry to identify the products that need to be kept together so as to encourage cross sales. An interesting aspect behind this algorithm is that historical invoices are mined to identify the products that are bought together.

There are several off-the-shelf algorithms available to perform market-basket analysis. Some of them are Apriori, equivalence class transformation (ECLAT), and frequent pattern growth (FP-growth). We will learn to solve our problem of recommending jokes to users through applying the Apriori algorithm on the Jester jokes dataset. We will now learn the theoretical aspects that underpin the Apriori algorithm.

...

Content-based recommendation engine

A recommendation engine that is solely based on the explicit or implicit feedback received from customers is termed as content-based recommendation system. Explicit feedback is the customer's expression of the interest through filling in a survey about preferences or rating jokes of interest or opting for newsletters related to the joke or adding the joke on the watchlist, and so on. Implicit feedback is more of a mellowed-out approach where a customer visits a page, clicks on a joke link, or just spends time reading a joke review on an e-commerce page. Based on the feedback received, similar jokes are recommended to the customers. It may be noted that content-based recommendations do not take into consideration the preferences and feedback of other customers in the system; instead, it is purely based on the personalized feedback from the...

Building a hybrid recommendation system for Jokes recommendations

We see that both content-based filtering and collaborative filtering have their strengths and weaknesses. To overcome the issues, organizations build recommender systems that combine two or more technique and they are termed hybrid recommendation models. An example of this is a combination of content-based, IBCF, UBCF, and model-based recommender engine. This takes into account all the possible aspects that contribute to making the most relevant recommendation to the user. The following diagram shows an example approach followed in hybrid recommendation engines:

Sample approach to hybrid recommendation engine

We need to note that there is no standard approach to achieving a hybrid recommendation engine. In order to combine recommendations, here are some suggested strategies:

  • Voting: Apply voting among the recommendation...

Summary

In this chapter, we used the recommenderlab library extensively to build the various types of joke-recommendation engines based on the Jester jokes dataset. We also learned about the theoretical concepts behind the methods.

Recommender systems is an individual ML area on its own. This subject is so vast that it cannot be covered in just one chapter. Several types of recommendation systems exists and they may be applied to datasets in specific scenarios. Matrix factorization, singular-value decomposition approximation, most popular items, and SlopeOne are some techniques that may be employed to build recommendation systems. These techniques are outside the scope of this chapter as these are rarely used in business situations to build recommendation systems, and the aim of the chapter is provide exposure to more popular techniques. Further learning on recommendation engines...

References

While the recommenderlab library is super popular in the R community, this is not the only choice for building a recommendation system. Here are some other popular libraries you may rely on to implement recommendation engines:

  • rrecsys: There are several popular recommendation systems, such as Global/Item/User-Average baselines, Item-Based KNN, FunkSVD, BPR, and weighted ALS for rapid prototyping. Refer to https://cran.r-project.org/web/packages/rrecsys/index.htmlImplementations for more information.
  • recosystem: The R wrapper of the libmf library (http://www.csie.ntu.edu.tw/~cjlin/libmf/) for recommender system using matrix factorization. It is typically used to approximate an incomplete matrix using the product of two matrices in a latent space. Other common names for this task include collaborative filtering, matrix completion, and matrix recovery. High-performance...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
R Machine Learning Projects
Published in: Jan 2019Publisher: PacktISBN-13: 9781789807943
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.
undefined
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

Author (1)

author image
Dr. Sunil Kumar Chinnamgari

Dr. Sunil Kumar Chinnamgari has a Ph.D. in computer science and specializes in machine learning and natural language processing. He is an AI researcher with more than 14 years of industry experience. Currently, he works in the capacity of lead data scientist with a US financial giant. He has published several research papers in Scopus and IEEE journals and is a frequent speaker at various meetups. He is an avid coder and has won multiple hackathons. In his spare time, Sunil likes to teach, travel, and spend time with family.
Read more about Dr. Sunil Kumar Chinnamgari