Skip to content

Machine learningBook recommender

Name a book you liked, and get ten more, learned from what Book-Crossing’s readers had on their shelves.

For a reader of

The Cat in the Hat

Dr. Seuss, 1957 · 66 readers in the data

Its ten

A blend of EASE, RP3beta and a text model, trained on every interaction with these books.

Or start from

The question

A recommender’s job is to put in front of a reader the books they would want next, learned from what they and readers like them already have. Book-Crossing is the classic data for it: readers’ ratings of books from 1 to 10, and a 0 where a reader has a book without rating it.

I built one that learns from every book a reader has, rated or not, and tested it the way a recommender is used: hide some of each reader’s books and see whether its ten bring them back.

How it works

What the data holds

The data is a table of readers and books. Where a reader rated a book, the cell holds the rating, 1 to 10; where they have the book without rating it, a 0. 62.3% of Book-Crossing’s 1,149,780 interactions are a 0. Read as “no opinion”, they would be thrown away; read as “this reader has this book”, they are the signal a recommender wants, which readers keep which books together. That reading alone lifts EASE’s NDCG@10 from 0.108 on the ratings to 0.150 on every interaction.

So every model below learns from a table of 1s and blanks: a 1 where a reader has a book, rated or not. The ratings come back only in the test, to say which hidden books count.

Six readers from the test, one dot a book. Switch what the model learns from: their ratings alone, their unrated books too, or every reader’s books, readers who rated nothing among them.

Two books and the readers they share

The oldest way to recommend from such a table is item to item: two books are alike when the same readers have both. Count the readers of both and divide by the square root of each book’s readers, ∣A∩B∣∣A∣ ∣B∣\frac{|A \cap B|}{\sqrt{|A|\,|B|}}, the cosine, so that two books read by everyone don’t look alike only for that. A reader’s ten are then the books most like the ones they have. Tuned on ratings set aside, as every model here is, it does best keeping each book’s 5 most alike and adding 10 under the square root, so that two little-read books sharing a reader or two don’t look alike by chance. Learning from every interaction, it finds one of a reader’s hidden books for 42.2% of readers, against 16.8% for the most popular books.

Pick two books: each circle’s area is its readers, the overlap the readers of both. The Lovely Bones shares more readers with The Cat in the Hat than Green Eggs and Ham does, 14 to 13, and is far less like it, 0.047 against 0.260: 14 of its 1,339 readers is nothing special.

EASE

EASE learns, for every book, how much each other book a reader has says about whether they have this one: one weight for every pair of books, fitted all at once in closed form, with nothing on the diagonal so a book can’t predict itself. With XX the table of readers and books, a 1 where a reader has a book:

P=(X⊤X+λI)−1,Bij=−PijPjj  (i≠j),Bii=0P = \left(X^\top X + \lambda I\right)^{-1}, \qquad B_{ij} = -\frac{P_{ij}}{P_{jj}} \ \ (i \neq j), \qquad B_{ii} = 0

A reader’s scores are xuBx_u B, the sum of the weights from the books they have. λ=50\lambda = 50 keeps the weights small where two books share few readers; I chose it on ratings set aside from the test. On its own EASE finds a hidden book for 46.4% of readers, an NDCG@10 of 0.161.

A model this small is not a step back. When Ferrari Dacrema, Cremonesi and Jannach tried to reproduce eighteen neural recommenders, six of the seven they could reproduce lost to simple, tuned methods like these. So I tuned every model the same way and show each beside the most popular books and item-to-item filtering.

RP3beta, and the popular book

RP3beta walks: from a book to the readers who have it, from each of them to the other books they have, and counts where the walk lands. Left at that, a bestseller is where every walk lands. So each book’s count is divided by a power of its own readers, and a book’s own kind rises above the books everyone has. With nin_i the readers of book ii and nun_u the books of reader uu:

Wij=1nj β∑u(xuini)α(xujnu)αW_{ij} = \frac{1}{n_j^{\,\beta}} \sum_u \left(\frac{x_{ui}}{n_i}\right)^{\alpha} \left(\frac{x_{uj}}{n_u}\right)^{\alpha}

α=0.8\alpha = 0.8 softens each step of the walk, β=0.6\beta = 0.6 is how hard a popular book is held back, and each book keeps its 1,000 strongest links. By shared readers alone, Divine Secrets of the Ya-Ya Sisterhood is in 77.6% of all the books’ lists; in the blend’s lists no single book is in more than 1.4% of them.

Pick a book and switch between its ten by shared readers alone and the model’s ten, the blend the demo runs. Each bar is a book’s readers, on one scale.

What the words add

A book few readers have gives the first two models little to go on. The text model reads instead: each book’s title, author, subjects and description from Open Library, weighted by TF-IDF, and its 20 nearest books by those words. For the less-read half of the books, the 1,167 with fewer than 81 readers in training, it finds 12.6% of their held-back ratings, where EASE finds 8.8%.

The blend, and the table in your browser

The three models score a reader on scales of their own, so the blend turns each model’s scores for a reader into how far each book stands above that reader’s average, in standard deviations, and weighs the three: 0.2 for EASE, 0.7 for RP3beta and 0.1 for the words, the weights chosen on ratings set aside from the test.

s(u,i)=∑mwm rm(u,i)−μm(u)σm(u)s(u,i) = \sum_{m} w_m \, \frac{r_m(u,i) - \mu_m(u)}{\sigma_m(u)}

For a shelf in your browser I keep one table instead: each book’s 50 strongest links to other books, each model’s part on the blend’s scale and weighted, so that a shelf’s score for a book is a plain sum of links from the shelf’s books:

Cji=∑mwm Tm[j,i]σm(j)C_{ji} = \sum_m w_m \, \frac{T_m[j,i]}{\sigma_m(j)}
score(i)=∑j ∈ shelfCji\text{score}(i) = \sum_{j \,\in\, \text{shelf}} C_{ji}

TmT_m is model mm’s table of book-to-book weights and σm(j)\sigma_m(j) the spread of its row jj, the scale a reader of book jj alone is scored on. The links are stored as book ids in 16 bits and strengths in 8, 496 kB in all, loaded the first time a shelf has two books. Because the score is a sum, each recommendation can say exactly which of your books brought it, and how much of it. On the same test the table finds a hidden book for 47.9% of readers and the full blend for 48.2%: a difference of −0.3 points (95% interval −1.6 to +1.0), within the test’s reach.

The test

For each of 2,271 readers a fifth of their ratings is hidden before any model sees the data. A model gets the rest and recommends ten books; it scores a hit when one of the ten is a hidden book the reader rated 4 or more. Every setting was chosen on ratings set aside for it, so the hidden ones were scored once, and each hit rate has its 95% interval.

A reader has a median of 3 such hidden books among 2,366, and ten guesses to find one. The blend finds one for 48 readers in 100.

One reader at a time from the test: the books the model learned from, the hidden ones face down, and the blend’s ten. Show the hidden books to see whether the ten found one: 6 of these 10 readers have a hit.

The books as a map

Laid out by who reads them together, the 2,366 books fall into neighbourhoods: Dr. Seuss beside Dr. Seuss, Austen beside the Brontës. I made the map from the blend’s table: each pair’s link made the same both ways, squeezed to 48 numbers a book, then laid out flat by t-SNE, which keeps each book’s near neighbours near and lets the distance between two neighbourhoods mean little. Near on the map means read by the same readers, not alike in subject.

It agrees with the lists: of a book’s ten, 50% lie among its 50 nearest dots, and the rest are where two dimensions can’t hold everything a book is near.

Pick a book, click any dot, or move with the arrow keys: the book and its ten light up, a line from it to each.

The data

The interactions
Book-Crossing’s 1,149,780 interactions of 105,283 readers with books. 62.3% of them are a 0: the reader has the book and gave it no rating.
The books
The 2,366 books with enough readers to learn from, each edition counted as its book: they hold 25.8% of all interactions, with their details from Open Library.
The test
A fifth of each of 2,271 readers’ ratings held back; a hit is one of them, rated 4 or more out of 10, in the ten. Every setting was chosen on ratings set aside for it, never on these (The test).

97.6% of all the ratings given are 4 or more, so a hit means the ten found a book the reader had, not one they loved.

What I found

Four things the data showed, and what each changed in how the recommender is built.

  1. 1. Most interactions are not ratings

    Of the 1,149,780 interactions of 105,283 readers with books, 62.3% are a 0: the reader had the book and gave it no rating. Of the ratings given, 8 is the most common.

    What it changed

    The recommender reads a 0 as “this reader has this book”, which is what a recommender predicts. At the same settings, adding the tested readers’ other books, nearly all unrated, lifts EASE’s NDCG@10 from 0.108 to 0.137, and adding other readers’ books too, to 0.150.

    Interactions, by the rating given
    1. 0 · no rating62.3%
    2. 10.2%
    3. 20.2%
    4. 30.5%
    5. 40.8%
    6. 54.4%
    7. 63.2%
    8. 76.6%
    9. 89.0%
    10. 95.9%
    11. 106.8%
  2. 2. Most books have one reader

    Book-Crossing lists 271,360 editions. Of the 270,151 that anyone has, 53.9% have exactly one reader, and a model can’t learn what goes with a book only one person has. The 2,366 books here are the other end: 3.3% of the editions, with 25.8% of all interactions.

    What it changed

    It keeps the titles with at least 10 ratings from readers with at least 10, and learns from every reader a book has, rated or not: the median book has 81 readers to learn from, against 12 if only those ratings counted.

    Editions, by how many readers have them
    1. 1 reader53.9%
    2. 2–430.9%
    3. 5–98.7%
    4. 10–495.7%
    5. 50–990.5%
    6. 100 or more0.3%
  3. 3. The most-read book was given away

    Wild Animus has 2,480 readers, 1.9 times the next book’s. Only 22.5% of them rated it, at 4.4 out of 10 on average, where the other most-read books average 7.5 to 9.0. Its publisher gave copies away through BookCrossing by the thousand, so having it says who received one, not who chose it.

    What it changed

    Models still learn from it, but it is never recommended: on readers alone it would top every list. The rule, more than 1,000 readers and a mean rating below 5, picks no other book.

    The 8 books with the most readersMean rating
    1. Wild Animus2,4804.4
    2. The Lovely Bones1,3398.2
    3. Divine Secrets of the Ya-Ya Sisterhood1,1547.8
    4. Angela's Ashes9018.2
    5. She's Come Undone8887.7
    6. The Da Vinci Code8618.4
    7. Harry Potter and the Sorcerer's Stone8029.0
    8. The Nanny Diaries7997.5
  4. 4. A title isn’t a book

    Book-Crossing files each rating under an edition’s ISBN, with its title as typed. Told apart by exact title, editions with different titles are different books, different books with the same title are one, and HTML codes stay in the titles.

    What it changed

    The recommender compares titles loosely, checks the author, and joins the editions Open Library files as one work, like the three titles of The Hobbit. So 196 books join two or more titles, and 75 titles split between authors. The books’ editions go from the 5,160 ISBNs that match a title exactly to 8,884, so a reader of any edition counts.

    Titles and books

    2,508titles2,366books

    In the dataAs a book
    “Bel Canto” and “Bel Canto: A Novel”One book, by Ann Patchett
    “Lightning”Two books, by Dean R. Koontz and by Danielle Steel
    “Angels & Demons”Angels & Demons

How well it recommends

Every model took the same test: readers with one of their held-back books in the ten, and NDCG@10, which also counts how high it sits.

The blend scores a hit for 48.2% of readers (95% interval 46.1–50.2%), item-to-item collaborative filtering for 42.2% (40.2–44.3%), and recommending the most popular books to everyone for 16.8%. The intervals don’t overlap: the gain is not luck in the test.

Readers with a hit in their tenNDCG@10
  1. The most popular books, for everyone16.8%0.033
  2. Item-to-item collaborative filtering42.2%0.140
  3. EASE, on every interaction46.4%0.161
  4. The blend: EASE, RP3beta and a text model48.2%0.172
All the numbers
ModelReaders with a hit95% intervalNDCG@10Books ever recommended
The most popular books, for everyone16.8%15.3–18.4%0.0332.1%
Item-to-item collaborative filtering42.2%40.2–44.3%0.14050.6%
EASE, on every interaction46.4%44.4–48.5%0.16159.0%
The blend: EASE, RP3beta and a text model48.2%46.1–50.2%0.17263.2%
The shelf’s table in your browser: each book’s 50 strongest links47.9%45.8–49.9%0.16770.4%

What I built

In Python, in stages, each answering one question under two rules: no held-back rating in training, and settings chosen only on ratings set aside for it.

  1. 1. Clean

    Book-Crossing files a rating under an edition’s ISBN and its title as typed. Titles compared loosely, the author checked and editions joined as Open Library files them, its 2,508 most-rated titles are 2,366 books, each with its details and cover from Open Library.

  2. 2. Test

    A fifth of each reader’s ratings held back, and a held-back book never in that reader’s training through any of its editions. Every setting chosen on ratings set aside for it, never on the test, and every hit rate with its 95% interval.

  3. 3. Model

    Trained on every interaction, books readers have without rating them included, and tuned EASE, RP3beta and a text model on the ratings set aside. Their blend scores an NDCG@10 of 0.172.

  4. 4. Show

    This page, with no server: one book’s ten are worked out ahead of time, and a shelf’s ten in your browser, from each book’s 50 strongest links in the same model.

The result in plain words

Readers who find one of their hidden books in its ten
48 in 100
readers get one of their own books back in its ten, after a fifth of each reader’s rated books was hidden from it.
item-to-item collaborative filtering: 42 in 100 · the most popular books, for everyone: 17
How many of the books it recommends to someone
63%
of the books reach some reader’s ten: it recommends across the shelf, not the same few bestsellers.
the most popular books, for everyone: 2.1%
The most any one book appears in its lists
1.4%
of the books’ lists hold its most-listed book, The Lovely Bones: no single title crowds out the rest.
2,365 different books across its 2,366 lists

It finds one of a reader’s own books for 48 readers in 100, against 42 for item-to-item collaborative filtering and 17 for the most popular books, and it spreads its lists across 63.2% of the books instead of returning the same few.

Much of the gain came from the data, not the model: reading a 0 as “this reader has this book” lifts EASE’s NDCG@10 from 0.108 on ratings alone to 0.150 (finding 1).

What I’d do next

  1. Test on time

    Book-Crossing has no dates, so the held-back ratings are a random fifth of each reader's, not what they read next. With dated data I'd hold back each reader's latest books.

  2. Ask readers

    Held-back ratings reward finding books readers had already found. An A/B test on what people choose would show whether its less obvious picks are ones they want.

Questions people ask

What is a book recommender system?

A program that puts in front of a reader the books they would want next, learned from what they and other readers already have. This one learned from 1,149,780 Book-Crossing interactions and, for 48 readers in 100, brings back one of their own hidden books in its ten. Try it at the top of the page with one book or a shelf of them.

How does collaborative filtering work?

It recommends from what readers have in common, not from what the books are about. Two books are alike when the same readers have both, and a reader is shown the books most like theirs. Item-to-item collaborative filtering finds a hidden book for 42.2% of readers here; EASE and RP3beta, which learn from the same table, do better (How it works).

What is the difference between collaborative filtering and content-based filtering?

Collaborative filtering learns from readers: who has what. Content-based filtering learns from the books themselves: their words, authors and subjects. The first is strong where many readers have a book, the second where few do; the blend here uses both, and on the less-read half of the books the text model finds 12.6% of the hidden ratings against EASE’s 8.8%.

What is implicit feedback?

What a person does rather than what they say: a book on their shelf, a film watched, a song played. Hu, Koren and Volinsky showed how to learn from it when ratings are few. In Book-Crossing 62.3% of the interactions are a book kept without a rating, and learning from them lifts EASE’s NDCG@10 from 0.108 to 0.150.

How do Netflix's and Amazon's recommendations work?

Neither publishes its whole system. Amazon described its own in 2003 as item-to-item collaborative filtering: for each product, the products bought with it, worked out ahead of time, which is what this page does for one book. Netflix’s public prize, from 2006 to 2009, made matrix factorization the best-known way to learn from a ratings table.

How do I get book recommendations based on books I like?

Put them on a shelf at the top of this page: search for a book, then add more. The ten are worked out in your browser from every book on the shelf, and each says which of yours it came from. The more books, the more the list reflects the shelf as a whole and not one book.

Which metrics measure a recommender system?

Here, three. The hit rate: the share of readers with one of their hidden books in the ten (48.2% for the blend). NDCG@10, which also counts how high the hit sits (0.172). And coverage, the share of all books that reach someone’s ten (63.2%), so a model can’t score well by naming the same bestsellers to everyone.

What is the Book-Crossing dataset?

Ratings collected by Cai-Nicolas Ziegler in 2004 from Book-Crossing, a community whose members leave books for others to find: 1,149,780 interactions of 105,283 readers with books, each a rating from 1 to 10 or a 0 for a book kept without one. It is one of the standard sets for book recommenders; I use the 2,366 books with enough readers to learn from.

What is EASE?

Embarrassingly Shallow Autoencoders, from Harald Steck in 2019: a model with one layer, one weight for every pair of items, fitted in closed form in a few lines of numpy. It is simple and hard to beat. Here it finds a hidden book for 46.4% of readers alone, and it is one of the blend’s three models.

Further reading

References

  • Steck, H. (2019). Embarrassingly Shallow Autoencoders for Sparse Data. WWW ’19. arXiv:1905.03375. doi:10.1145/3308558.3313710.
  • Paudel, B., Christoffel, F., Newell, C., Bernstein, A. (2017). Updatable, Accurate, Diverse, and Scalable Recommendations for Interactive Applications. ACM Transactions on Interactive Intelligent Systems 7(1). doi:10.1145/2955101.
  • Christoffel, F., Paudel, B., Newell, C., Bernstein, A. (2015). Blockbusters and Wallflowers. RecSys ’15, 163–170. doi:10.1145/2792838.2800180.
  • Ferrari Dacrema, M., Cremonesi, P., Jannach, D. (2019). Are We Really Making Much Progress? A Worrying Analysis of Recent Neural Recommendation Approaches. RecSys ’19, 101–109. arXiv:1907.06902. doi:10.1145/3298689.3347058.
  • Ziegler, C.-N., McNee, S. M., Konstan, J. A., Lausen, G. (2005). Improving Recommendation Lists Through Topic Diversification. WWW ’05, 22–32. doi:10.1145/1060745.1060754.
  • Hu, Y., Koren, Y., Volinsky, C. (2008). Collaborative Filtering for Implicit Feedback Datasets. ICDM 2008, 263–272. doi:10.1109/ICDM.2008.22.
  • Linden, G., Smith, B., York, J. (2003). Amazon.com Recommendations: Item-to-Item Collaborative Filtering. IEEE Internet Computing 7(1), 76–80. doi:10.1109/MIC.2003.1167344.
  • Gansner, E. R., Hu, Y., Kobourov, S. G., Volinsky, C. (2009). Putting Recommendations on the Map. RecSys ’09, 345–348. arXiv:0906.5286. doi:10.1145/1639714.1639784.
  • Herlocker, J. L., Konstan, J. A., Riedl, J. (2000). Explaining Collaborative Filtering Recommendations. CSCW ’00, 241–250. doi:10.1145/358916.358995.
  • Chatti, M. A., Guesmi, M., Muslim, A. (2023). Visualization for Recommendation Explainability: A Survey and New Perspectives. arXiv:2305.11755.

Ratings: the Book-Crossing data (Cai-Nicolas Ziegler, 2004), from Kaggle’s Book Recommendation Dataset. Book details, descriptions and covers: Open Library (opens in a new tab).

Each list shows one edition of a book, and none includes Wild Animus (finding 3 above).