Data Analysis Behind Recommendation System: Great Book Reads
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.
Github | Linkedin
Data Science Introduction
Recommendation systems have gained huge popularity among eCommerce and online media in the last few years to increase user interaction. Many of our day-to-day choices are driven by personalized recommender systems that are made possible using common data and machine learning algorithms. Some common recommender systems are Netflix suggestions for movies, music on Spotify, Google Ads, and product recommendations on Amazon.
There are two major types of recommendation systems used by most businesses. CONTENT-BASED and COLLABORATIVE. Content-based recommender systems use item features to recommend similar products. For example, if I am a fan of Agatha Christie, the system will recommend me other books from the same author or cozy mysteries from other authors. Collaborative recommender system clusters similar types of users to recommend the item that one user from the cluster has recommended to the other users who did not try the item.
In this article, I have explored the basic concepts behind collaborative recommendation systems using the book feature dataset from Goodreads. As with any other machine learning project, I started with Exploratory Data Analysis and wrapped it up with codes for a basic user-based recommendation system.
Exploratory Data Analysis
Dataset
The data was collected from UCSD Book Graph. I used the complete book graph from the metadata of books and Book Reviews for this project. A subset of 150k books was used from the book graph dataset containing 27 features including Title, publishers, ratings, image_url, language, etc. The review dataset contained 10k rows of user-id, book id, and user rating which was sorted for books published between 2000-2017 from the book graph dataset. I have used RStudio for this project.
EDA
For exploratory data analysis, the following questions were investigated,
- Number of books published each year
- How does a number of pages affect popularity?
- Which books have the maximum versions?
- What are the most popular languages?
- How did the popularity of eBooks change in the last decade?
- Which format is most popular?
- How are average rating and popularity related?
- What ratings are more likely?
- Top 10 publishers and their popularity?
Data on Books Published Each Year
Fig 1 and Fig 2 give the number of publications between 1900-2017 from my dataset. It was seen most books in the dataset were between 2000 and 2017 and rows containing books from these years were filtered out. It was also observed that the number of publications increased after 2007. This is when kindle was launched and ebooks started gaining popularity.
Number of Pages
The number of ratings is considered an estimation of how many people read the book or the popularity. As seen from the scatterplots of the number of pages vs average rating (Fig 4) and the number of pages vs the number of ratings (Fig 5), thick books are less popular but mostly high rated with very few outliers. Most popular books are between 200-400 pages long.
Data on Number of Authors and Different Versions
My dataset has books up to 51 authors. It is seen that books with more than 10 authors are highly rated although the relation is not linear since there were many highly rated single-author books but very few books with more than 10- authors are rated below 3 (Fig 5).
There are few books with many versions including languages, formats, and editions. The most number of versions from my dataset is Stolz und Vorurteil (Fig 6), which is german for Pride and Prejudice. There are 3000 versions of this Jane Austen 1813 novel published in different languages.
Language & format
Analyzing from the bar chart in Fig 8, English is the most popular language followed by Spanish, Arabic, and French. Also, the kindle has a great impact on people's reading behavior. kindle is more popular than all other forms of ebooks.
Data on Average Rating & Popularity
As the number of readers increases, the average rating starts dropping. Reviewing Fig 9, no books with average rating 5 has more than 500 reviews. In the case of books, an average rating of 3.5 or above can be considered safe as long as popularity is concerned. There are critics even for the best works. IT IS DIFFICULT TO KEEP EVERYONE HAPPY!
Publishers
CreateSpace, a self-publishing platform owned by amazon has published the maximum number of books(Fig 10) from the dataset. The books published by CreateSpace are rated high (Fig 11) and are quite popular to acquire the top 10 most number of ratings from my dataset. This is another example of more and more people adapting kindle. Vintage, the New York-based publishing house is the most popular publisher with many highly-rated books.
Popularity of eBooks Data
After Kindle's release in 2007, the popularity of ebooks has grown tremendously. As seen from Fig 13, the number of ebooks sored after 2011. This is when kindle provided its self-publishing platform for freelance and independent writers. In 2011, kindle helped amazon reach $10 Billion in revenue.
Recommendation System
For this project, I have investigated collaborative recommender systems. There are two types of collaborative recommendation systems. Item-Based and User-Based.
Item Based Collaborative Recommender System
The item-based recommender system model was proposed by amazon in 1998. It takes into account the similarity between items and the frequency of users buying the items together. For example, if a user is viewing Agatha Christie's 'the murder of roger Ackroyd, the model will look for users who have already recommended the book before, and then check for books recommended/bought by those users. In the picture (Fig 14), this is done by matching ratings of the books purchased with the current book.
User-Based Collaborative Recommender System
In a user-based recommender system, the similarity between users is checked.
As shown in Fig 15, both user1 and user2 are Agatha christie fans and have recommended 3 of her books (who doesn't love her mysteries!!!). Now,user2 recommended Sherlock Holmes, which is a similar genre too. Based on this behavior the model will recommend user1 Sherlock Holmes too. This is a user-based recommender model.
The Basic Maths Behind Gathered Data
To visualize a collaborative recommender system model, we have to first understand the user-item matrix and similarity function. A user-item matrix generated from the book review dataset is shown in Fig 16. Each row represents a user and each column represents a book. The entries are the ratings given by each user to the books they have read. There are a lot of NAs within the matrix since every user hasn't read every book. Due to the ease of computation, a similarity function is introduced.
There are many types of similarity functions, like cosine similarity, Pearson’s correlation coefficient, Euclidean distance, etc. For this project, the cosine similarity function is used (Fig 17). As shown in the matrix (Fig 18), the cosine similarity function can be implemented row-wise (user-based) or column-wise (item-based). The cosine similarity between U1 and U5 is maximum and so the book that U5 has read and U1 has not read will be recommended to U1. For the item-based approach, the cosine similarity between B1 and B5 is maximum, so the user who reads B1 will be recommended B5 if they have not already read B5.
Data Analysis
Top Recommended Books for User 2955
Using the model the following books were recommended to User 2955. The ones with image URLs retrieved the images. Meanwhile, the count column represents the number of similar users and the rating column returned the rating given by those users to the given book.
Output:
Future Works
For future work, I am planning to build a hybrid content-based & collaborative recommender system and implement some findings from EDA for filtering (for example, thick books are less popular). A scalable dashboard with the codes at the back end can be generated which could be used by book eCommerce platforms. To test the final model, A/B testing is an essential component as there is no way of telling the effectiveness of a recommendation system model without being implemented for real users.
References
Mengting Wan, Julian McAuley, "Item Recommendation on Monotonic Behavior Chains", in RecSys'18.
Mengting Wan, Rishabh Misra, Ndapa Nakashole, Julian McAuley, "Fine-Grained Spoiler Detection from Large-Scale Review Corpora", in ACL'19.