The goal of this project is to build a personalized movie recommendation system using R.
In Assignment 3A, I used the Global Baseline Estimate (GBE) to predict movie ratings based on the overall average, user bias, and movie bias.
For this assignment, I will extend that analysis by implementing a personalized recommendation algorithm.
The new system will use movie rating patterns to recommend movies based on each user’s preferences.
2 Research Questions
How can movie rating patterns be used to generate personalized recommendations?
Which movies should be recommended to users based on their previous ratings?
How accurate are the personalized rating predictions?
How does the personalized recommender compare with the Global Baseline Estimate?
3 Data Source
This project uses the same movie rating survey dataset from Assignment 3A: Global Baseline Estimate.
The dataset contains ratings provided by different users across six movies. These ratings will be used to develop a personalized recommendation system.
Dataset: movie_ratings.csv
File Location: Data/movie_ratings.csv
The original CSV file will be included in the GitHub repository to support reproducibility.
3.1 Data Import and Dataset Overview
The movie ratings dataset was imported from a CSV file using R and the readr package.
The following table summarizes the dataset used to develop the personalized recommendation system.
Show code
# Import the original movie ratings datasetmovie_ratings <- readr::read_csv("Data/movie_ratings.csv",show_col_types =FALSE)# Verify required variablesstopifnot(all(c("critic", "movie", "rating") %in%names(movie_ratings)))# Create dataset summarydataset_summary <-tibble(Description =c("Number of observations","Number of users","Number of movies","Number of variables","Rating scale","Data format","Import status" ),Value =c(nrow(movie_ratings),n_distinct(movie_ratings$critic),n_distinct(movie_ratings$movie),ncol(movie_ratings),"1 to 5","CSV","Successfully imported" ))# Display formatted tabledataset_summary %>%kable(caption ="Table 1. Movie Ratings Dataset Overview",align =c("l", "c") ) %>%kable_styling(bootstrap_options =c("striped", "hover", "condensed" ),full_width =FALSE,position ="center" )
Table 1. Movie Ratings Dataset Overview
Description
Value
Number of observations
61
Number of users
16
Number of movies
6
Number of variables
3
Rating scale
1 to 5
Data format
CSV
Import status
Successfully imported
The dataset was successfully imported and contains 61 observed ratings from 16 users across six movies. The three variables are critic, movie, and rating. These variables will be used to develop the personalized recommendation system.
3.2 Variable Description
The dataset contains three variables used to identify users, movies, and ratings.
Show code
variable_description <-tibble(Variable =c("critic","movie","rating" ),Type =c("Character","Character","Numeric" ),Description =c("Identifies the user who rated the movie","Identifies the movie being rated","Rating assigned by the user from 1 to 5" ))variable_description %>%kable(caption ="Table 2. Variable Description",align ="l" ) %>%kable_styling(bootstrap_options =c("striped", "hover", "condensed" ),full_width =FALSE,position ="center" )
Table 2. Variable Description
Variable
Type
Description
critic
Character
Identifies the user who rated the movie
movie
Character
Identifies the movie being rated
rating
Numeric
Rating assigned by the user from 1 to 5
3.3 Data Preview
The following table displays the first six observations from the original dataset.
The dataset contains 96 possible user-movie combinations, including 61 observed ratings and 35 missing ratings.
These missing combinations will be considered when generating personalized movie recommendations in the Code Base.
4 Proposed Recommendation Algorithm
I will use item-to-item collaborative filtering to build the personalized recommendation system.
This algorithm identifies similarities between movies based on ratings from users who have rated the same movies.
The model will follow these steps:
Import and validate the movie rating data.
Organize the ratings into a user-movie matrix.
Calculate similarities between movies using observed ratings.
Identify movies similar to those previously rated by each user.
Predict ratings for movies that users have not rated.
Generate personalized movie recommendations.
This approach allows the system to use individual user preferences instead of relying only on overall rating averages.
5 Recommendation Output
The recommender will produce two main outputs:
Predicted ratings: Estimated ratings for movies that a user has not rated.
Top-N recommendations: A ranked list of movies with the highest predicted ratings for each user.
The recommendations will exclude movies that the user has already rated.
6 Model Evaluation
The model will be evaluated using a hold-out method. A portion of the observed ratings will be reserved for testing, while enough ratings will be retained for training and calculating movie similarities.
The same training and testing data will be used to compare the personalized recommender with the Global Baseline Estimate.
Prediction accuracy will be evaluated using Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE).
7 Expected Results
I expect the personalized recommendation system to produce different recommendations for users based on their rating histories.
The comparison with the Global Baseline Estimate will help determine whether item-to-item collaborative filtering improves prediction accuracy.
The results will also demonstrate how user preferences can influence movie recommendations.
8 Limitations
This project has several limitations:
The dataset contains a small number of movies and observed ratings.
Some users may have limited rating histories.
Missing ratings may reduce the number of movies that can be compared.
Item similarities may be unreliable when there are few overlapping ratings.
The personalized method may not always outperform the baseline model.
These limitations will be considered when interpreting the results.
9 Next Steps
The Code Base will implement the proposed algorithm in R, generate personalized recommendations, evaluate prediction accuracy, and visualize the results.
The final analysis will compare the personalized recommender with the previous Global Baseline Estimate.
10 Recommendation Algorithm
I implemented item-to-item collaborative filtering to generate personalized movie recommendations.
The model uses Pearson correlation to identify similar movies based on observed ratings. It also incorporates the Global Baseline Estimate to support predictions when sufficient positive similarity information is unavailable.
11 Code Base: Implementation
11.1 User–Movie Utility Matrix
The first step is to organize the movie ratings into a user-movie utility matrix.
Each row represents a user, and each column represents a movie. The values show the ratings assigned by each user.
Missing values indicate movies that users have not rated. These values will remain missing because they represent unknown preferences rather than negative ratings.
The utility matrix contains 16 users and six movies.
This matrix helps identify patterns in movie ratings and provides the foundation for item-to-item collaborative filtering.
The original numeric matrix preserves missing values for similarity calculations and rating predictions.
12 Research Questions: Implementation and Results
12.1 Research Question 1: How can movie rating patterns be used to generate personalized recommendations?
Movie rating patterns can be used to identify movies that receive similar ratings from the same users.
I implemented item-to-item collaborative filtering using Pearson correlation. Similarities are calculated only when at least three users have rated both movies. Negative similarities are excluded, and a shrinkage factor reduces the influence of small overlaps.
Show code
# Function to calculate movie similaritiescalculate_similarity <-function(data) { matrix_data <- data %>%select(critic, movie, rating) %>%pivot_wider(names_from = movie,values_from = rating ) %>% tibble::column_to_rownames("critic") %>%as.matrix() movies <-colnames(matrix_data) n_movies <-length(movies) similarity <-matrix(0,nrow = n_movies,ncol = n_movies,dimnames =list(movies, movies) )diag(similarity) <-1for (i inseq_len(n_movies -1)) {for (j inseq.int(i +1, n_movies)) { x <- matrix_data[, i] y <- matrix_data[, j] common <-!is.na(x) &!is.na(y) overlap <-sum(common)if (overlap >=3) { x_common <- x[common] y_common <- y[common]if (sd(x_common) >0&&sd(y_common) >0) { correlation <-cor(x_common, y_common) score <-max(0, correlation) * overlap / (overlap +3) similarity[i, j] <- score similarity[j, i] <- score } } } } similarity}# Global Baseline Estimate from Assignment 3Afit_gbe <-function(data) { mu <-mean(data$rating) user_bias <-tapply( data$rating, data$critic, mean ) - mu movie_bias <-tapply( data$rating, data$movie, mean ) - mulist(mu = mu,user_bias = user_bias,movie_bias = movie_bias )}# Predict using the Global Baseline Estimatepredict_gbe <-function(critic, movie, model) { bu <-unname(model$user_bias[critic]) bi <-unname(model$movie_bias[movie])if (is.na(bu)) bu <-0if (is.na(bi)) bi <-0 prediction <- model$mu + bu + bias.numeric(pmax(1, pmin(5, prediction)))}# Predict using item-to-item collaborative filteringpredict_cf <-function( critic, movie, data, baseline, similarity) { base_prediction <-predict_gbe( critic, movie, baseline ) known <- data[ data$critic == critic, , drop =FALSE ]if (nrow(known) ==0||!movie %in%rownames(similarity)) {return(base_prediction) } weights <-as.numeric( similarity[movie, known$movie] ) valid <-is.finite(weights) & weights >0if (!any(valid)) {return(base_prediction) } previous_predictions <-vapply( known$movie[valid],function(m) predict_gbe(critic, m, baseline),numeric(1) ) residuals <- known$rating[valid] - previous_predictions prediction <- base_prediction +sum(weights[valid] * residuals) /sum(weights[valid])as.numeric(pmax(1, pmin(5, prediction)))}# Calculate movie similarity using all observed dataitem_similarity <-calculate_similarity(movie_ratings)# Prepare movie similarity tablesimilarity_pairs <-as.data.frame(as.table(item_similarity)) %>%transmute(Movie_1 =as.character(Var1),Movie_2 =as.character(Var2),Similarity =as.numeric(Freq) ) %>%filter( Movie_1 < Movie_2, Similarity >0 ) %>%arrange(desc(Similarity))similarity_pairs %>%kable(caption ="Table 6. Movie Similarity Results",col.names =c("Movie 1","Movie 2","Similarity" ),digits =3,align =c("l", "l", "c") ) %>%kable_styling(bootstrap_options =c("striped", "hover", "condensed", "responsive" ),full_width =FALSE,position ="center",font_size =12 )
Table 6. Movie Similarity Results
Movie 1
Movie 2
Similarity
Frozen
Jungle Book
0.504
Captain America
Frozen
0.431
Captain America
Pitch Perfect 2
0.417
Captain America
Jungle Book
0.392
Deadpool
Pitch Perfect 2
0.352
Pitch Perfect 2
Star Wars Force
0.349
Captain America
Star Wars Force
0.300
Captain America
Deadpool
0.236
Deadpool
Star Wars Force
0.197
Frozen
Pitch Perfect 2
0.047
Jungle Book
Pitch Perfect 2
0.044
Deadpool
Frozen
0.043
Answer:
The algorithm identifies movies with similar rating patterns and uses these similarities to estimate a user’s preferences. Positive similarities help determine which previously rated movies can provide useful information for predicting an unrated movie.
The model also uses the Global Baseline Estimate when sufficient positive similarity information is unavailable.
12.2 Research Question 2: Which movies should be recommended to users based on their previous ratings?
The recommendation system predicts ratings for movies that each user has not rated.
The model then ranks these movies and selects up to two recommendations per user.
# Identify users who have rated every movieusers_without_recommendations <-setdiff(sort(unique(movie_ratings$critic)),unique(recommendation_predictions$critic))# Count users who can receive recommendationsusers_with_recommendations <-n_distinct( recommendation_predictions$critic)
Answer:
The recommendation system generates a ranked list of unrated movies for each user. Movies with higher predicted ratings are recommended first.
The model evaluated 35 missing user-movie combinations.
Out of 16 users, 12 users received personalized recommendations.
The remaining 4 users (Charley, Max, Parshu, Sreejaya) had already rated all six movies. Therefore, the system did not recommend additional movies to these users.
The recommendations exclude movies that users have already rated, allowing the model to focus on new movies based on individual preferences.
12.3 Research Question 3: How accurate are the personalized rating predictions?
I used a hold-out evaluation to measure prediction accuracy.
One rating was randomly selected for testing from each user with at least three observed ratings. All remaining ratings were used for training.
The same training and testing sets were used for both models.
12.3.1 Evaluation Metrics: MAE and RMSE
To evaluate the accuracy of the recommendation system, I used two common metrics: Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE).
Mean Absolute Error (MAE)
MAE measures the average absolute difference between the actual movie ratings and the predicted ratings.
\[
MAE = \frac{1}{n}\sum_{i=1}^{n}|r_i-\hat{r}_i|
\]
Where:
\(n\) = Number of predictions
\(r_i\) = Actual movie rating
\(\hat{r}_i\) = Predicted movie rating
For example, an MAE of 0.80 means that the predictions differ from the actual ratings by an average of 0.80 rating points.
A lower MAE indicates better prediction accuracy.
Root Mean Squared Error (RMSE)
RMSE measures the square root of the average squared difference between actual and predicted ratings.
The following table compares the actual ratings reserved for testing with the predictions generated by both recommendation models.
The test dataset contains 11 observed ratings that were excluded from the training process.
For each observation, the table shows the actual rating, the Global Baseline Estimate prediction, the personalized recommendation prediction, and their absolute errors.
The table shows how closely each model predicted the 11 actual movie ratings.
The absolute error is the difference between the actual rating and the predicted rating, without considering whether the prediction was higher or lower.
MAE is calculated as the average absolute error across all test ratings. RMSE uses the squared prediction errors, giving greater weight to larger mistakes.
These results help explain how the evaluation metrics were calculated and allow a more detailed comparison between both models.
Answer:
The personalized recommendation model achieved an MAE of 1.237 and an RMSE of 1.508.
These results were calculated using 11 held-out ratings. Lower MAE and RMSE values indicate more accurate predictions.
Because the dataset is small, the results should be interpreted carefully.
12.4 Research Question 4: How does the personalized recommender compare with the Global Baseline Estimate?
The final step compares the prediction errors of both recommendation methods.
The Global Baseline Estimate uses the overall average, user bias, and movie bias. The personalized recommender adds information from similar movies and the user’s previous rating patterns.
The following checks confirm that the dataset contains valid ratings, the training and testing datasets do not overlap, and the recommendation system does not recommend previously rated movies.
The validation checks confirm that both models were evaluated on ratings excluded from training and that personalized recommendations contain only unrated movies.
Answer:
The Global Baseline Estimate obtained an MAE of 1.269 and an RMSE of 1.538.
The personalized recommender obtained an MAE of 1.237 and an RMSE of 1.508.
Compared with the Global Baseline Estimate, the personalized model reduced MAE and reduced RMSE on the test data.
The comparison shows whether movie similarities improve prediction accuracy beyond the Global Baseline Estimate. Since only a small number of ratings were tested, the results do not establish which method would perform better on a larger dataset.
13 Comparison with Assignment 3A
13.1 Case Study: Param’s Movie Recommendations
In Assignment 3A, I used the Global Baseline Estimate (GBE) to predict ratings for two movies that Param had not rated: Jungle Book and Pitch Perfect 2.
The GBE recommended Jungle Book because it had the higher predicted rating.
In Assignment 11, I used the same dataset to compare the original predictions with the new personalized recommendation system.
This comparison helps explain how collaborative filtering changes movie recommendations based on user preferences.
Table 10. Assignment 3A vs. Personalized Recommendations
Movie
GBE Prediction
Personalized Prediction
Jungle Book
3.47
2.25
Pitch Perfect 2
2.28
2.63
13.2 Interpretation
The Global Baseline Estimate recommended Jungle Book with a predicted rating of approximately 3.47, compared with 2.28 for Pitch Perfect 2.
The personalized recommender produced different results. It predicted approximately 2.25 for Jungle Book and 2.63 for Pitch Perfect 2.
As a result, the personalized model recommended Pitch Perfect 2 instead of Jungle Book.
This difference shows how item-to-item collaborative filtering can change recommendations by considering movie similarities and individual user preferences.
However, these predictions do not prove which recommendation is more accurate because Param’s actual ratings for these movies are unknown.
The hold-out evaluation using MAE and RMSE provides a separate comparison of the prediction accuracy of both models.
14 Conclusion
This project extends Assignment 3A by implementing a personalized movie recommendation system using item-to-item collaborative filtering.
Both projects use the same dataset of 61 movie ratings from 16 users across six movies.
The Global Baseline Estimate predicts ratings using the overall average, user bias, and movie bias. The personalized recommender extends this method by considering similarities between movies and individual rating patterns.
The comparison for Param shows that the two methods produce different recommendations. The Global Baseline Estimate recommends Jungle Book, while the personalized model recommends Pitch Perfect 2.
Prediction accuracy was also evaluated using MAE and RMSE on the same testing data. These metrics help determine whether the personalized model improves predictions compared with the baseline.
Because the dataset is small, the results should be interpreted carefully. Future improvements could include more movie ratings and repeated model evaluations.
Overall, this project demonstrates how collaborative filtering can extend a baseline recommendation system and produce personalized movie recommendations.
15 Appendix: AI Assistance
ChatGPT was used to help understand the assignment requirements, organize the project, improve English writing, and provide guidance on the proposed recommendation methodology and evaluation methods.
AI assistance was also used to explain collaborative filtering, personalized recommendations, and the comparison with the Global Baseline Estimate.
I selected the recommendation approach based on my previous Assignment 3A. I am responsible for reviewing the methodology, preparing the dataset, implementing the R code, verifying the results, and interpreting the final conclusions.