Assignment Week 3-3A Codebase

Author

Yalda Azamee

Published

December 1, 2026

Approach

I will use the movie-rating survey I collected in Week 2 (10 participants, 6 movies, ratings from 1 to 5) to implement a Global Baseline Estimate recommendation system in R. I will save the survey ratings as a CSV file on GitHub, using anonymous IDs (U01–U10), so the code can be run on any computer.

Following the course spreadsheet, I will calculate the overall mean rating, each movie’s average rating, and each user’s average rating. For every movie a user has not rated, I will estimate the rating as:

Estimate = mean rating + (movie average − mean rating) + (user average − mean rating)

For each user, I will recommend the unrated movie with the highest estimated rating.

Anticipated Challenges

  • Missing ratings: a blank rating means the participant has not seen the movie. I will exclude missing values when calculating averages, not treat them as zero.
  • User with no ratings: U05 did not rate any movie, so a user average cannot be calculated. For U05, I will use only the mean rating and the movie’s effect.
  • Users with no unrated movies: some participants rated all six movies, so there is nothing to recommend to them.
  • Estimates outside the scale: the formula can produce a value above 5, so I will cap estimates at 5.

Load the Data

The ratings are the same Week 2 survey responses (10 participants, 6 movies), saved as a CSV file on GitHub so the code runs on any computer. A blank rating means the participant had not seen the movie.

library(tidyverse)

url <- "https://raw.githubusercontent.com/YaldaAzamee/Assignment-Week-3/main/movie_ratings.csv"
ratings <- read_csv(url, show_col_types = FALSE)

ratings |>
  pivot_wider(names_from = title, values_from = rating) |>
  knitr::kable(caption = "Ratings by user (NA = not seen)")
Ratings by user (NA = not seen)
user_id The Wolf of Wall Street The Godfather Spider-Man Home Alone Titanic Harry Potter
U01 2 5 3 3 4 2
U02 5 5 5 NA 4 4
U03 5 5 4 5 5 5
U04 NA NA 5 3 5 5
U05 NA NA NA NA NA NA
U06 4 NA 3 5 3 NA
U07 5 4 4 5 5 3
U08 NA 5 4 NA 4 NA
U09 4 4 4 4 4 4
U10 4 5 3 3 5 3

Global Baseline Estimate

The algorithm from the course spreadsheet:

Estimate = mean movie rating + (movie average − mean) + (user average − mean)

mean_rating <- mean(ratings$rating, na.rm = TRUE)

movie_avg <- ratings |>
  group_by(title) |>
  summarise(movie_avg = mean(rating, na.rm = TRUE)) |>
  mutate(movie_bias = movie_avg - mean_rating)

user_avg <- ratings |>
  group_by(user_id) |>
  summarise(n_rated = sum(!is.na(rating)),
            user_avg = mean(rating, na.rm = TRUE)) |>
  mutate(user_bias = user_avg - mean_rating)

round(mean_rating, 3)
[1] 4.13
knitr::kable(movie_avg, digits = 3, caption = "Movie averages")
Movie averages
title movie_avg movie_bias
Harry Potter 3.714 -0.416
Home Alone 4.000 -0.130
Spider-Man 3.889 -0.242
The Godfather 4.714 0.584
The Wolf of Wall Street 4.143 0.012
Titanic 4.333 0.203
knitr::kable(user_avg, digits = 3, caption = "User averages")
User averages
user_id n_rated user_avg user_bias
U01 6 3.167 -0.964
U02 5 4.600 0.470
U03 6 4.833 0.703
U04 4 4.500 0.370
U05 0 NaN NaN
U06 4 3.750 -0.380
U07 6 4.333 0.203
U08 3 4.333 0.203
U09 6 4.000 -0.130
U10 6 3.833 -0.297

U05 did not rate any movie, so the user average is NaN. For U05, I set the user bias to 0, so the estimate uses only the mean and the movie’s bias. Because the rating scale is 1 to 5, any estimate above 5 is capped at 5.

estimates <- ratings |>
  filter(is.na(rating)) |>
  left_join(movie_avg, by = "title") |>
  left_join(user_avg, by = "user_id") |>
  mutate(user_bias = replace_na(user_bias, 0),
         estimate  = mean_rating + movie_bias + user_bias,
         estimate  = pmin(estimate, 5))   # ratings cannot be above 5

estimates |>
  select(user_id, title, estimate) |>
  knitr::kable(digits = 2, caption = "Estimated ratings for unrated movies")
Estimated ratings for unrated movies
user_id title estimate
U02 Home Alone 4.47
U04 The Wolf of Wall Street 4.51
U04 The Godfather 5.00
U05 The Wolf of Wall Street 4.14
U05 The Godfather 4.71
U05 Spider-Man 3.89
U05 Home Alone 4.00
U05 Titanic 4.33
U05 Harry Potter 3.71
U06 The Godfather 4.33
U06 Harry Potter 3.33
U08 The Wolf of Wall Street 4.35
U08 Home Alone 4.20
U08 Harry Potter 3.92

Recommendations

For each user, I recommend the unrated movie with the highest estimated rating.

recommendations <- estimates |>
  group_by(user_id) |>
  slice_max(estimate, n = 1) |>
  select(user_id, recommended_movie = title, estimate)

knitr::kable(recommendations, digits = 2, caption = "Recommended movie for each user")
Recommended movie for each user
user_id recommended_movie estimate
U02 Home Alone 4.47
U04 The Godfather 5.00
U05 The Godfather 4.71
U06 The Godfather 4.33
U08 The Wolf of Wall Street 4.35

Users U01, U03, U07, U09, and U10 rated all six movies, so there is no unrated movie to recommend to them.

Conclusion

The overall mean rating is 4.13. The Godfather has the highest movie average, so it is recommended to every user who has not seen it. Because the Global Baseline Estimate is non-personalized, it only shifts the estimate up or down by how generous the user is and how well the movie is rated in general.

AI Use

Anthropic. (2026). Claude Opus 5.5 [Large language model]. https://claude.ai. Accessed December 1, 2026. Used to help understand the assignment and check the R code.