Movie Regularization

Regularization is a technique that permits us to penalize large estimates that come from small sample sizes, thus shrinking the estimates torwards zero and minimizing the residual mean squared errors.
When applying the movie effect, many obscure movies get high rating prediction, but in fact, they have low ratings, thus showing large mistake residuals in prediction.

If we look at the top 10 best and worse predicted movie effect $b_{i}$, we see that both have many obscure movies. Many of them were rated by very few people, in most cases just one. With few users ratings, we have more uncertainty, therefore larger $b_{i}$ are more likely to happen.

These obscure movies are considered noisy estimates (outliers) and should not be considered in our models. We solve this problem by applying regularization, since the data has many outliers.
The new movie effect $b_{i}$ is estimated by minimizing the following equation, which considers the RMSE and a penalty term:
$\frac{1}{N} \sum_{u,i} (y_{u,i} - \mu - b_{i})^{2} + \lambda\sum_{i} b_{i}^{2}$
So with regularization, the estimate $b_{i}$ that minimizes the equation is given by:
$\hat{b}_{i}(\lambda) = \frac{1}{\lambda + n_{i}} \sum_{i=1}^{n_{i}} (Y_{u,i} - \hat{\mu})$
Since $\lambda$ is a tunning parameter of our model, we will apply 10-fold cross validation to find the best value for it.

The tunned $\lambda$ with the lowest residual mean squared error is $\lambda = 4.5$. We use this $\lambda$ to fit the regularized model with the entire training set.

To see the regularization effect, we plot the regularized estimate versus the least square estimates, with the size of the circle showing the size of n_i.

It is possible to see that for movies that have only 1 rating, the regularized estimate $b_{i}$ is much smaller than the original estimate, shrinking towards zero.
Applying regularization on the data, we look for the new top 10 best movies (highest $b_{i}$) and 10 worst movies (lowest $b_{i}$).

By calculating the residual mean squared error over the test set, we can see that we improved our model.

Movie and user effects

The next step is to apply the average for users, with the users effect $b_{u}$, in addition to the movie effect $b_{i}$.
$Y_{u,i} = \mu + b_{i} + b_{u} + \varepsilon_{u,i}$
We select only those that have rated over 100 movies. Below we can see through their histogram that the users also has a significant variability.

The user bias can be calculated by subtracting the overall average and movie effect from each user average rating.

Below we calculate the residual mean squared error with the two bias.

Movie and User Regularization

We can apply regularization to the users effect as well. The new equation to be minimized will have both movie and user effect in the penalty term:
$\frac{1}{N} \sum_{u,i} (y_{u,i} - \mu - b_{i} - b_{u})^{2} + \lambda(\sum_{i} b_{i}^{2} + \sum_{u} b_{u}^{2})$
So with regularization, the estimates $b_{u}$ and $b_{i}$ that minimize the equation are given by:
$\hat{b}_{i}(\lambda) = \frac{1}{\lambda + n_{i}} \sum_{i=1}^{n_{i}} (Y_{u,i} - \hat{\mu})$
$\hat{b}_{u}(\lambda) = \frac{1}{\lambda + n_{u}} \sum_{u=1}^{n_{u}} (Y_{u,i} - \hat{\mu} - \hat{b}_{i})$
Since $\lambda$ is a tunning parameter of our model, we will apply 10-fold cross validation to find the best value for it.

For both movie and user effect, the optimal tunned parameter is $\lambda = 4.75$. Now we use the entire training set to fit the model and predict it on the test set. It can be observed that the residual mean squared error improved a little.