Recommendation systems attempt to predict the preference of a user for an item. The goal typically being to then present the user with the items they are most likely to prefer.
Recommendation systems have been increasingly used in recent years in online retailing. Perhaps the most well-known example being movie recommendations due to the Netflix prize. Films, books, music, food and other purchasable items are all commonly the subject of recommendations systems. The same concepts have also been applied to research articles, collaborators, romantic partners, news items, travel routes, and many other areas.
There are two main types of recommendation systems:
Collaborative filtering utilizes the preferences of many users, basing recommendations on what other users with similar preferences to you have liked previously. Collaborative filtering systems do not need to know anything about the users or items, eliminating the need to develop features that accurately capture differences between users or items.
Content-based filtering utilizes item descriptions and user profiles or past/current preferences to identify similar items to recommend.
Both approaches have limitations and an increasingly popular approach is hybrid recommendations systems. These systems attempt to combine both collaborative and content-based filtering. Content-based filtering can aid collaborative filtering by providing initial recommendations when there is insufficient data on the users preferences, and provide a coarse starting point for the sparse set of labels on user preferences.
Another approach used to supplement user preferences is to use multiple different types of user feedback. In addition to explicit ratings for items more implicit feedback can be used such as viewing duration.
Performance can be evaluated with metrics we are already familar with such as root mean square error. However, accuracy is not the only factor in determining user satisfaction or the utility of the system. For example, a recommendation system can return several almost identical items and get a very low RMSE but a user will likely prefer a more diverse set of recommendations.
The Surprise scikit package implements several strategies for creating recommendation systems.
In [11]:
from surprise import SVD
from surprise import Dataset
from surprise import evaluate, print_perf
# Load the movielens-100k dataset (download it if needed),
# and split it into 3 folds for cross-validation.
data = Dataset.load_builtin('ml-100k')
In [12]:
data.split(n_folds=3)
# We'll use the famous SVD algorithm.
algo = SVD()
# Evaluate performances of our algorithm on the dataset.
perf = evaluate(algo, data, measures=['RMSE', 'MAE'])
print_perf(perf)
In [16]:
import pandas as pd
from surprise import GridSearch
param_grid = {'n_epochs': [20, 50], 'lr_all': [0.002, 0.005, 0.01],
'reg_all': [0.01, 0.02, 0.04]}
grid_search = GridSearch(SVD, param_grid, measures=['RMSE', 'FCP'])
grid_search.evaluate(data)
results_df = pd.DataFrame.from_dict(grid_search.cv_results)
In [17]:
results_df
Out[17]:
In [18]:
results_df[['FCP', 'RMSE', 'n_epochs', 'reg_all', 'params']].sort_values('RMSE')
Out[18]:
In [ ]: