Data Analysis

We will investigate some of machine learning recommendation systems approaches to create specific recommendations for users, based on previous rating analysis. These are based on the Netflix challenge, which occurred in 2006.
The GroupLens research lab has a database of over 27 millions ratings for over 58,000 movies by more than 280,000 users.
We use here the movielens dataset, which is a small sample of the GroupLens dataset. The movielens has 100,004 entries, with rating from 671 users in a total of 9,066 movies.
We will proceed with some data analysis first.

We look here a small subset of ratings from 6 users over 5 movies. There are many movies without ratings from users.

This code shows how the dataset matrix is sparse, with a random sample of 100 movies and 100 users, by showing with colored dots where there are ratings.

The following distribution shows that some movies are more rated than others, since there are blockbusters watched by millions and independent movies watched by just a few.

In similar way, there are users that are more active than others at rating movies.

By plotting the number of ratings by year the movie came out, we notice there is an increase on the average around thes 90s.

Among the movies that came out since 1990, we show the top 10 with highest average number of ratings per year.

By analyzing the data it is possible to notice that the most frequently rated movies tend to have higher average ratings, since more people watch popular movies. This trend can be verified in the following graphic.

The movies dataset has a column with information of the movie genres. However this column includes every genre that applies to the movie and some may contain more than one genre.
Since a movie with only one genre may differ from other that incorporates several genres, we consider every combination of genres as unique and compute the average and standard error for each one with more than 1,000 ratings.
It is possible to see that there is a strong evidence of genre effect over the ratings.

For the prediction algorithms we start by creating the training and test sets. We include in the test set only movies and users that also appear in the training set.

We need to quantify a loss function, to compare the different machine learning algorithms. The Netflix challenge used the typical error, based on the residual mean squared error: (user $u$ and movie $i$)
$RMSE = \sqrt{\frac{1}{N}\sum_{u,i} (\hat{y}_{u,i} - y_{u,i})^{2}}$

Average classifier

Same average

We start with the simplest model. We predict the same rating for all movies, regardless of user or movie, with all differences explained by random variation:
$Y_{u,i} = \mu + \varepsilon_{u,i}$
In this model, the estimate that minimizes the residual mean squared error is the least squares estimate of $\mu$, which in this case, is the average of all ratings over all users.

We can compute the residual mean squared error for this simple model:

Movie effects

We can improve our model by assigning different average for each movie $i$ by adding the movie effect (or bias) $b_{i}$:
$Y_{u,i} = \mu + b_{i} + \varepsilon_{u,i}$
The movie bias can be calculated by subtracting the overall average from each movie average rating.

Many movies have substantial $b_{i}$ estimates. Movies with $b_{i} = 1.5$ implies a perfect five-star rating, since the average is $\hat{\mu} = 3.5$
By applying the movie average to each movie, we can compute the new residual mean squared error of this model on the test set.