Assignment W3 A

Author

Muhammad Imran

Introduction

The problem involves implementing a Global Baseline Estimate (GBR) recommender system in R using the given movie-rating dataset. The dataset is provided in Excel format and contains ratings from 17 critics for six different movies. To implement the recommender system, the first step is to understand the concept and methodology of the Global Baseline Estimate. This involves identifying the key components required for the calculation, including the overall average rating, user bias, and movie bias. These values must then be prepared and processed through an appropriate R data pipeline to calculate the baseline estimates and generate movie recommendations. The final objective is to use these calculations to produce predicted ratings and identify the recommended movie based on the Global Baseline Estimate.

Global Baseline Estimator (GBE)

The Global Baseline Estimate is an item-based, non-personalized recommender system that uses historical user ratings to estimate how highly a movie is likely to be rated. Unlike personalized recommendation systems, such as content-based filtering or item-item collaborative filtering, the Global Baseline Estimate does not primarily rely on finding users with similar preferences. Instead, it establishes a baseline prediction for each movie by considering the overall rating behavior in the dataset, individual user rating tendencies, and the tendency of each movie to receive ratings above or below the overall average.

The algorithm is based on three main components:

1. Overall Average Rating (Global Mean)

The overall average rating represents the mean rating across all movies and all users in the dataset. It provides a general indication of the rating level within the entire survey. This value serves as the starting point for estimating the expected rating of a movie.

2. User Bias

User bias captures the tendency of an individual user to rate movies either higher or lower than the overall average. For example, some users may generally give ratings of 4 or 5, while others may be more conservative and usually give ratings of 2 or 3. The user bias measures this difference and adjusts the baseline estimate accordingly.

3. Movie/Item Bias

Movie bias represents the tendency of a particular movie to receive ratings that are consistently higher or lower than the overall average rating. For example, if a movie generally receives ratings above the global average, it will have a positive movie bias. Conversely, a movie that tends to receive lower ratings will have a negative movie bias.

Why it is called “Global Baseline”?

It is because of the fact that this recommender system does not need any of the sophistication. It neither needs and calculation nor complex computation such as content-based filtering, item-item collaborative filtering or neural networks. Rather, it is used for benchmarking, for example; if a more sophistical system is not producing substantially better results than the GBE. In that case the GBE is preferred and low cost. For this assignment, it is important that we have to calculate the global mean, user biases, user biases and after that generate predicting ranges from out survey data.

Given data (in excel format)

This table represents a User-Item Movie Rating Matrix, which serves as the foundational dataset for building recommendation algorithms (such as Collaborative Filtering or Global Baseline Estimates).

Structure Breakdown

• Rows (Critics/Users): Represents 16 individual reviewers (e.g., Burton, Charley, Dan).

• Columns (Movies/Items): Represents 6 feature films (Captain America, Deadpool, Frozen, Jungle Book, Pitch Perfect 2, and Star Wars Force).

• Cells (Ratings): Numerical scores assigned by critics on a 1-to-5 scale.

Key Characteristics

• Sparse Matrix / Missing Data: Blank cells indicate unobserved data—movies a critic hasn’t watched or rated yet (e.g., Burton has only rated Jungle Book and Star Wars Force). Out of 96 total possible rating cells, only 61 are populated.

Approach / Application of the algorithm in the given data

To implement the Global Baseline Estimate recommender system, I will first prepare the movie ratings data in a tidy format, with each row representing a single user–movie rating. I will then calculate the overall mean rating, followed by user and movie bias terms to capture deviations from the global average. These components will be combined to generate predicted ratings for each user–movie pair. Finally, I will review the results, handle missing values appropriately, and verify that the implementation is consistent with the algorithm provided in the spreadsheet and produces reproducible results.

Conclusion

I implemented a Global Baseline Estimate recommender system on the movie ratings dataset to predict missing user ratings. Following the methodology outlined in the reference spreadsheet, the model combines the global mean rating with user-specific and movie-specific bias terms. These predicted values were then used to generate a top movie recommendation for each user. While non-personalized, this approach establishes a transparent, highly interpretable benchmark against which more complex collaborative filtering models can be evaluated.

Implementataion

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyr)
library(httr)
library(readxl)
github_url <- "https://github.com/Muhammad-Imran91/607/raw/main/MovieRatings.xlsx"
temp_file <- tempfile(fileext = ".xlsx")
download.file(github_url, destfile = temp_file, mode = "wb")
# 3. Read the MovieRatings sheet
df_raw <- read_excel(temp_file, sheet = "MovieRatings")

# Verify download was successful
print(head(df_raw))
# A tibble: 6 × 7
  Critic   CaptainAmerica Deadpool Frozen JungleBook PitchPerfect2 StarWarsForce
  <chr>             <dbl>    <dbl>  <dbl>      <dbl>         <dbl>         <dbl>
1 Burton               NA       NA     NA          4            NA             4
2 Charley               4        5      4          3             2             3
3 Dan                  NA        5     NA         NA            NA             5
4 Dieudon…              5        4     NA         NA            NA             5
5 Matt                  4       NA      2         NA             2             5
6 Mauricio              4       NA      3          3             4            NA
df_long <- df_raw %>%
  pivot_longer(
    cols = -Critic,
    names_to = "Movie",
    values_to = "Rating"
  ) %>%
  drop_na(Rating)
# 5. Calculate Global Mean (mu = 3.9344)
mu <- mean(df_long$Rating)
# 6. Calculate User Bias (b_u = User Average - mu)
user_bias <- df_long %>%
  group_by(Critic) %>%
  summarize(b_u = mean(Rating) - mu)
# 7. Calculate Movie Bias (b_i = Movie Average - mu)
movie_bias <- df_long %>%
  group_by(Movie) %>%
  summarize(b_i = mean(Rating) - mu)
# 8. Compute Global Baseline Estimates (mu + b_u + b_i) for all Critic-Movie combinations
predictions <- expand.grid(
  Critic = unique(df_raw$Critic),
  Movie = colnames(df_raw)[-1]
) %>%
  left_join(user_bias, by = "Critic") %>%
  left_join(movie_bias, by = "Movie") %>%
  mutate(
    b_u = coalesce(b_u, 0),
    b_i = coalesce(b_i, 0),
    Predicted_Rating = mu + b_u + b_i
  )
# 9. Reshape predictions into a User-Item Matrix
global_baseline_matrix <- predictions %>%
  select(Critic, Movie, Predicted_Rating) %>%
  pivot_wider(names_from = Movie, values_from = Predicted_Rating)
# Display the output matrix
print(as.data.frame(global_baseline_matrix))
      Critic CaptainAmerica Deadpool   Frozen JungleBook PitchPerfect2
1     Burton       4.338301 4.510018 3.792846   3.965574      2.779859
2    Charley       3.838301 4.010018 3.292846   3.465574      2.279859
3        Dan       5.338301 5.510018 4.792846   4.965574      3.779859
4  Dieudonne       5.004968 5.176685 4.459513   4.632240      3.446526
5       Matt       3.588301 3.760018 3.042846   3.215574      2.029859
6   Mauricio       3.838301 4.010018 3.292846   3.465574      2.279859
7        Max       3.671634 3.843352 3.126180   3.298907      2.113193
8     Nathan       4.338301 4.510018 3.792846   3.965574      2.779859
9      Param       3.838301 4.010018 3.292846   3.465574      2.279859
10    Parshu       4.004968 4.176685 3.459513   3.632240      2.446526
11 Prashanth       5.138301 5.310018 4.592846   4.765574      3.579859
12    Shipra       4.338301 4.510018 3.792846   3.965574      2.779859
13  Sreejaya       5.004968 5.176685 4.459513   4.632240      3.446526
14     Steve       4.338301 4.510018 3.792846   3.965574      2.779859
15     Vuthy       3.938301 4.110018 3.392846   3.565574      2.379859
16   Xingjia       5.338301 5.510018 4.792846   4.965574      3.779859
   StarWarsForce
1       4.219420
2       3.719420
3       5.219420
4       4.886087
5       3.469420
6       3.719420
7       3.552753
8       4.219420
9       3.719420
10      3.886087
11      5.019420
12      4.219420
13      4.886087
14      4.219420
15      3.819420
16      5.219420
# Example Output: How Param would rate Pitch Perfect 2
param_pitch_perfect <- predictions %>%
  filter(Critic == "Param" & Movie == "PitchPerfect2") %>%
  pull(Predicted_Rating)

cat("\nParam's Global Baseline Estimate for Pitch Perfect 2:", round(param_pitch_perfect, 2), "\n")

Param's Global Baseline Estimate for Pitch Perfect 2: 2.28