Reader small image

You're reading from  Hands-On Machine Learning with C++

Product typeBook
Published inMay 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781789955330
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Kirill Kolodiazhnyi
Kirill Kolodiazhnyi
author image
Kirill Kolodiazhnyi

Kirill Kolodiazhnyi is a seasoned software engineer with expertise in custom software development. He has several years of experience building machine learning models and data products using C++. He holds a bachelor degree in Computer Science from the Kharkiv National University of Radio-Electronics. He currently works in Kharkiv, Ukraine where he lives with his wife and daughter.
Read more about Kirill Kolodiazhnyi

Right arrow

Recommender Systems

Recommender systems are algorithms, programs, and services whose main task is to use data to predict which objects (goods or services) are of interest to a user. There are two main types of recommender systems: content-based and collaborative filtering. Content-based recommender systems are based on data collected from specific products. They recommend objects to a user that are similar to ones the user has previously acquired or shown interest in. Collaborative filtering recommender systems filter out objects that a user might like based on the reaction history of other similar users of these systems. They usually consider the user's previous reactions, too.

In this chapter, we'll look at the implementation of recommender system algorithms based on both content and collaborative filtering. We are going to discuss different approaches for implementing...

Technical requirements

An overview of recommender system algorithms

A recommender system's task is to inform a user about an object that could be the most interesting to them at a given time. Most often, such an object is a product or service, but it may be information—for example, in the form of a recommended news article.

Despite the many existing algorithms, we can divide recommender systems into several basic approaches. The most common are as follows:

  • Summary-based: Non-personal models based on the average product rating
  • Content-based: Models based on the intersection of product descriptions and user interests
  • Collaborative filtering: Models based on interests of similar user groups
  • Matrix factorization: Methods based on the preferences matrix decomposition

The basis of any recommender system is the preferences matrix. The preferences matrix has all users of the service laid on one...

Understanding collaborative filtering method details

In this section, let's formalize the recommender system problem. We have a set of users, , a set of items, (movies, tracks, products, and so on), and a set of estimates, . Each estimate is given by user , object , its result , and, possibly, some other characteristics.

We are required to predict preference as follows:

We are required to predict personal recommendations as follows:

We are required to predict similar objects as follows:

Remember—the main idea behind collaborative filtering is that similar users usually like similar objects. Let's start with the simplest method, as follows:

  • Select some conditional measures of similarity of users according to their history of ratings.
  • Unite users into groups (clusters) so that similar users will end up in the same cluster: .
  • Predict the item's user rating...

Examples of item-based collaborative filtering with C++

Let's look at how we can implement a collaborative filtering recommender system. As a sample dataset for this example, we use the MovieLens dataset provided by GroupLens from the research lab in the Department of Computer Science and Engineering at the University of Minnesota: https://grouplens.org/datasets/movielens/. They provide a full dataset with 20 million movie ratings and a smaller one for education, with 100,000 ratings. We recommend starting with the smaller one because it allows us to see results earlier and detect implementation errors faster.

This dataset consists of several files, but we are only interested in two of them: ratings.csv and movies.csv. The rating file contains lines with the following format: the user ID, the movie ID, the rating, and the timestamp. In this dataset, users made ratings on...

Summary

In this chapter, we discussed what recommender systems are and the types of these that exist today. We studied two main approaches to building recommender systems: content-based recommendations and collaborative filtering. We identified two types of collaborative filtering: user-based and item-based. We looked at the implementation of these approaches, and their pros and cons. We found out that an important issue in the implementation of recommender systems is the amount of data and the associated large computational complexity of algorithms. We considered approaches to overcome computational complexity problems, such as partial data updates and approximate iterative algorithms, such as ALS. We found out how matrix factorization can help to solve the problem with incomplete data, improve the generalizability of the model, and speed up the calculations. Also, we implemented...

Further reading

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Machine Learning with C++
Published in: May 2020Publisher: PacktISBN-13: 9781789955330
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
Kirill Kolodiazhnyi

Kirill Kolodiazhnyi is a seasoned software engineer with expertise in custom software development. He has several years of experience building machine learning models and data products using C++. He holds a bachelor degree in Computer Science from the Kharkiv National University of Radio-Electronics. He currently works in Kharkiv, Ukraine where he lives with his wife and daughter.
Read more about Kirill Kolodiazhnyi