Book Recommendation System

We designed and developed a book recommendation system that recommends the next few books for our target users based on their own reading tastes.

Keywords
Recommendation, Collaborative Filtering, R Shiny App
Members
Eda Zhang, Radhika Kulkarni, Daye Kang, Eunhee Sung
My contribution
Collaborative Filtering, Exploratory Data Analysis, UI mockup
Year
2.2020 – 5.2020
Book Recommendation System

Project Description

Executive Summary

In this project, we designed and developed a book recommendation system that recommends the next few books for our target users based on their own reading tastes. Here is the current version of the app: edaxplor.shinyapps.io/book_v4. The data sources we used came from the UCSD Book Graph website and a Book Recommender Project on Kaggle. Considering the scope of our project and our target users, mainly children younger than 15 years old and educators of children in that age group, we used two datasets from the websites: a book dataset containing the fantasy and children's book genres and a rating dataset with users' ratings of the books. Logistic and linear regression models were tested for overall model adequacy and showed some linear relationships between the variables.

To figure out the best algorithm for our product, we analyzed and compared the datasets using both supervised and unsupervised learning. The results showed that the unsupervised learning methods performed better than the supervised learning methods. Among the different supervised learning techniques we implemented, the linear model, the fast and frugal tree, outperformed the other models, including the generalized linear model and the nonlinear XGBoost model. We included the details of our analysis in the model interpretation section. In terms of unsupervised learning, we found that the collaborative filtering clustering method fit the goal of our project best. Other clustering methods we implemented included dimensionality-reduction techniques with UMAP and K-means. Ultimately, we used the UBCF algorithm to make recommendations to our users based on their own book preferences, and we captured the main ideas of the books through TF-IDF analysis of their descriptions.

As a result, a book recommender was developed as an R Shiny app with genre and rating filters. After users select their favorite genre and rate books that they have read, the model suggests three books. As a reference, a word cloud is also drawn to show which words are frequently used in each book.

It is not easy to recommend a book to others because people spend money to buy a book and time to read it. There are some ways to help readers find the next book they might like, such as browsing best-selling books displayed by genre in bookstores or searching for and reading other people's reviews online. These resources might help people decide on a book they may like, but they do not always work. Since every person has their own reading tastes, picking a book they might like takes time. To save them time and make their decisions easier, the book recommendation system uses an algorithm that can save them the trouble of searching online, reading all the reviews, and comparing the results with their tastes.

In this project, a book recommendation algorithm was built for two genres: children's books and fantasy books. Therefore, anyone who would like to read a new book, especially fantasy lovers, children, their parents, and educators who teach children under the age of 15, is a target user for this application.

Data Sources & Preprocessing

Data Set

To develop the application, we used four datasets. The main dataset used to develop the model was the Genre dataset. The dataset was collected in late 2017 from goodreads.com, with several files updated in May 2019. It has 26 columns and 1,242 rows: book_id, authors, average_rating, goodreads_book_id, country_code, description, format, image_url, is_ebook, isbn, isbn13, language_code, link, num_pages, publication_year, publisher, ratings_count, series, similar_books, title, title_without_series, URL, and work_id.

Next, three datasets contributed by Philipp Spachtholz on Kaggle were combined into one rating dataset: ‘ratings.csv’ (3 columns, 194,941 rows: book_id, user_id, rating), ‘book_tags.csv’ (3 columns, 999,912 rows: goodreads_book_id, tag_id, count), and ‘tags.csv’ (2 columns, 34,252 rows: tag_id, tag_name). The combined rating dataset has the same column, “book_id,” as the genre dataset, so the two datasets can be used together to build the book recommendation application.

Data Analysis

Review ratings can be biased because people tend to leave ratings when they are very satisfied or disappointed. Ratings are the most important values for a recommendation application because people receive suggestions for highly rated books first. Before creating the algorithm, we drew a distribution plot to check whether the average ratings in the dataset were biased. Figure 1 shows that the data is approximately normally distributed, with an average of 3.90, so the average ratings are not biased.

Figure 1

Figure 1. Distribution plot of average rating

Next, a logistic regression model was used because the response variable, genre, is binary. The model checks whether there is a relationship between the dependent variable, genre, and the independent variables: average rating, number of pages, publication year, rating count, text review count, and title length. Using the glm function in R, a model was obtained, as shown in Figure 2.

Figure 2

Figure 2. Summary of logistic regression

Since the z-values for the number of pages and title length variables are very small, the coefficients of the two variables are significant. This result explains the dataset well because the dependent variable consists of two genres. The average number of pages in children's books is not expected to be as high as that in adult books, and the average title length of children's books is 25% greater than that of fantasy books.

Next, the model was checked against the normality assumption by examining the normal probability plot. Figure 3 shows the normal probability plot of the residuals, which follows an approximately normal distribution.

Figure 3

Figure 3. Q-Q plot of residuals for logistic regression

This dataset was intended for an online recommendation system, so the average rating of books was considered the most significant variable. A linear regression model was fitted with average rating as the outcome and the other variables as predictors to check their relationships with average rating. Since average rating is a numeric value, a multiple linear regression model was used.

Figure 4

Figure 4. Summary of linear regression

Since the p-value for the number of pages variable is very small, its coefficient is significant, suggesting that the number of pages has a linear relationship with the average rating. We then checked whether the model met the normality assumption by examining the normal probability plot in Figure 5. All of the points follow the straight line in the plot, indicating that the residuals follow a normal distribution.

Figure 5

Figure 5. Q-Q plot of residuals for linear regression

Preprocessing of Data

The data was processed to better suit the machine learning algorithms through binary encoding of categorical variables, scaling of variables, and removal of missing values and columns with NA values.

Collaborative Filtering

Figure 6

Figure 6. The collaborative filtering process

We chose collaborative filtering because it is widely used for recommendations. It assumes that if person A has the same opinion as person B on one issue, person A is more likely to share person B's opinion on a different issue than that of a randomly chosen person.

Figure 6 illustrates how CF works. First, you create a matrix in a certain format, with columns representing items and rows representing users. You then put this matrix into CF algorithms to get recommendations. (Source: Item-Based Collaborative Filtering Recommendation Algorithms.) We followed three steps for the recommendation process, referencing the process from Kaggle's book recommendation example: data processing and exploration, finding user neighbors, and making recommendations.

The first step is data processing and exploration. At this stage, we removed duplicate ratings and then removed users who had rated fewer than three books. We selected a subset of users to speed up calculations and explored the cleaned dataset. Titles with five or seven words had slightly higher ratings. After that, we looked at the top-rated and most popular books. Next, we created a matrix for the CF algorithm.

Figure 7

Figure 7. Exploratory data analysis

Figure 8

Figure 8. Top 10 top-rated books and top 10 popular books

Figure 9

Figure 9. Matrix for UBCF

The second step is finding user neighbors. At this stage, we found similar users by comparing the books they both liked. In this case, we set the current user as 794 and then found users who had rated the same books. We normalized the users' ratings and sorted the users according to similarity. For this, we used Pearson correlation. Figure 11 shows the similarities between the current user and 30 randomly selected users, plotted with qgraph.

Figure 10

Figure 10. Process of finding user neighbors

Figure 11

Figure 11. Similarities between users

Finally, in step three, the algorithm recommends books that best fit the target user based on the preferences of similar users.

Figure 12

Figure 12. Best recommendations for the user

Model Interpretation and Explanation

Supervised Learning

To select the most suitable techniques for our project, we implemented both supervised and unsupervised techniques to investigate how well they performed on the dataset. The datasets we used contain different types of data: categorical, interval, ratio, and text, with more categorical data than other types. Therefore, classification models fit our goal better.

We implemented three types of classification models: Fast and Frugal decision tree analysis, XGBoost, and a generalized linear model. To measure the performance of each model, we created an ROC curve. As shown in Figure 13, all three supervised models performed poorly on the task, with only small differences between them. The result suggested that supervised learning might not be the best approach for our project.

Figure 13

Figure 13. Performance ROC curve

The result from the Fast and Frugal decision tree in Figure 14 indicated that publication year, number of pages, genre, and number of reviews were the most important variables in deciding whether a book would be recommended to a user.

Figure 14

Figure 14. Result from the Fast and Frugal decision tree

On the other hand, GLM and XGBoost identified rating count, number of pages, and text review count, along with publication year, as the top four important features in their models.

Figure 15

Figure 15. Linear vs. nonlinear: GLM vs. XGBoost

Although the preliminary analysis using supervised learning offered some insights into the dataset, these models did not fulfill our goal of recommending the next few books to our target users. Moreover, to run the models, we eliminated a few variables because of the constraints that certain models placed on data types. This procedure improved the efficiency of training and building the models, but we may also have lost useful information in the process.

Unsupervised Learning: Cluster Analysis

The purpose of our app was to filter and recommend books to users. One of the state-of-the-art practices in building recommendation filtering systems is to use collaborative filtering algorithms, which are often considered clustering algorithms. Additionally, unsupervised learning outperformed supervised learning in finding potential patterns across different types of data.

The ‘clValid’ package in R was used to carry out clustering on the dataset. Intuitively, the following parameters are the most relevant to users when recommending the best books: average rating, genre, format, and book length (number of pages). These features were incorporated into our analysis after preprocessing, which included binary encoding of categorical variables, scaling of the data points, and removal of NA or missing values.

We concluded that K-means clustering would suit our dataset better than hierarchical clustering for two main reasons. First, our dataset was large, and binary encoding would increase the number of variables that the algorithm had to handle. Second, K-means allows more flexibility across clusters because a data point can be reassigned to another cluster.

Using the clValid package, we obtained a cluster plot with the ‘kmeans’ method for 11 clusters. We validated 11 as the optimal number of clusters using silhouette and stability validation methods across a range of 2 to 11. The highest silhouette score was associated with 11 clusters, as shown in the fviz_nbclust plot below.

Figure 16

Figure 16. The silhouette method for the optimal number of clusters

Figure 17

Figure 17. Cluster plot

The resulting clusters are very close to and overlap with one another. Dimensionality-reduction methods such as UMAP and PCA can help resolve this issue. The UMAP function was used on our dataset to reduce it to two dimensions and produce cleaner, tighter clusters.

Figure 18

Figure 18. K-means clustering based on UMAP-transformed data

The green points in the plot appear to be outliers, but they are actually a cluster of 10 points. A deeper analysis revealed that they belonged to the “Audio CD” format, with lengths ranging from 0 to 10 pages. This seems peculiar because audiobooks should not intuitively have ‘pages’ associated with them.

The ‘kmeans’ function in R can also be used to fit the data. It is less complex and does not offer the same functionality as clValid, but with a little analysis, it allows for greater interpretability of the different characteristics within each cluster. Here, the kmeans function was used with 11 clusters, and the data was filtered to obtain data points belonging to cluster 2: books in the ‘Children's Books’ genre and ‘Board Book’ format.

Figure 19

Figure 19. K-means clustering using the ‘kmeans’ function

Collaborative Filtering

Nevertheless, it would not be easy for our app to rank all the books within the same cluster, so the accuracy of the model might be compromised. In addition, both models used dimensionality-reduction methods, which reduce their interpretability for the audience. A few algorithms have proved effective, and Riesterer et al. (2020) examined how noise levels affect the performance of each algorithm. As they suggested, UBCF and IBCF outperformed MFA in a noisier dataset environment. In our app, the algorithm code contributed through Kaggle includes both UBCF and IBCF algorithms. However, it would be helpful to conduct heuristic evaluations with our users to better understand their experience.

Figure 20

Figure 20. Performance graph: UBCF vs. IBCF vs. MFA

Text Analysis: TF-IDF Word Cloud

Data: book descriptions. Features: captures some information and runs quickly. Challenges: different languages and a small dataset.

Figure 21

Figure 21. Word cloud example

Application and Conclusions

Basic Prototype

First, we came up with a simple prototype consisting of three parts. In the first column, people can choose genres and rate books they like. In the second column, they can filter recommendations. Finally, they can see the recommended books. Using the arrow button, users can view more recommendations. Word clouds are created from each book's description and help users quickly understand what the recommended book is about.

Figure 22

Figure 22. Basic prototype

Demonstration Application

Based on the R Shiny example on Kaggle, we developed two new features: genre selection filtering and a word cloud for recommended books. Because we used a different dataset consisting of children's books and fantasy books, we made recommendations based on the user's genre selection. After users receive a recommendation, they can view the word clouds and understand the unique features of the recommended books. You can find the test version here: edaxplor.shinyapps.io/book_v4.

Conclusion

The demo showed that UBCF works well for book recommendations. However, we think the prototype can be improved further by strengthening trust and persuasion. These are areas for future improvement. Conducting user testing would also be an effective way to evaluate our service.

  • We used a username and bookshelf as a title to create a sense of personalized service.
  • We separated the user's bookshelf into two parts: a ‘Reading Now’ shelf and a ‘To Read’ shelf. By doing so, the algorithm can understand the user's current and future interests.
  • By showing other users' bookshelves, we wanted to give users the feeling that the website is a book-reading community. We think we can also add curated book sections to support augmented AI-human collaboration.
  • Users can like or dislike a recommendation. Based on this feedback, the algorithm can reflect the user's preferences and apply them to future recommendations.
Figure 24

Figure 24. Detailed prototype for future development

References

← Back to projects