3A Global Baseline Estimate

Author

Tenzin Thakuri

Introduction

The objective of this assignment is to implement a Global Baseline Estimate recommendation system in R using the last assignment’s movie rating data that I’d collected and provided spreadsheet algorithm Movie Ratings XLSX . There are two types of recommendation system algorithm, personalized and non personalized.

In this assignment, we are going to use “Global Baseline Estimate”.

Baseline Estimate=Global Mean+User Bias+Item Bias

Global Mean: The overall average rating across all items and all users in the dataset.

User Bias: How much a specific user’s rating tend to deviate from the global average.

Item Bias: How much a specific item’s rating deviate from the global average.

Global Baseline Estimate (often called a baseline predictor) is a non-personalized algorithm used in recommender system to predict how a user would rate a specific item.

Approach

First, I will reformat the TV episode ratings data to a format similar to the provided movie ratings spreadsheet.

Then, I will calculate each user’s average TV episode rating in R and store the results in a user_avg column. I will also calculate the global mean.

Next, I will calculate the average rating for each TV episode in R and store the results in a episode_avg column at the end of the records.

Then, I will identify any TV episode that is missing a rating for a particular user. For each missing rating, I will use the Global Baseline Estimate formula to calculate a predicted rating based on the available user ratings, episode ratings, and overall average rating. Then I’ll make sure the calculations are valid and reproducible.

Anticipated Challenges

Since I only have five users rating six TV episodes, there is a chance that some episodes will not be rated by certain users. This may result in missing ratings and could potentially introduce bias into the analysis. The small number of users may also make the average ratings less representative.

Code

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Import data set

url<-"https://raw.githubusercontent.com/lhamo07/Data-607-Assignment/refs/heads/Week3A-Global-Baseline-Estimate/tv_episodes_ratings_dataset.csv"

tv_episode_df<-read.csv(file = url)

Calculate user average

tv_episode_df<-tv_episode_df %>%
  group_by(user)%>%
  mutate(user_avg=mean(rating,na.rm=TRUE))
tv_episode_df
# A tibble: 30 × 4
# Groups:   user [5]
   user   tv_episodes     rating user_avg
   <chr>  <chr>            <int>    <dbl>
 1 Tenzin Squid Game           5      4.2
 2 Tenzin Emily in Paris       4      4.2
 3 Tenzin Ginny&Georgia        3      4.2
 4 Tenzin Brigerton            4      4.2
 5 Tenzin Wednesday            5      4.2
 6 Tenzin Stranger Things     NA      4.2
 7 Laura  Squid Game           4      4.4
 8 Laura  Emily in Paris       5      4.4
 9 Laura  Ginny&Georgia        4      4.4
10 Laura  Brigerton            5      4.4
# ℹ 20 more rows

Added a “user_avg” column that shows each user’s average rating for the episodes they rated.

Calculate global mean

global_mean <- tv_episode_df %>%
  ungroup() %>%
  summarise(global_mean = mean(rating, na.rm = TRUE))%>%
  pull(global_mean)
global_mean
[1] 4.35

calculated the global mean, which represents the overall average rating across all TV episodes and users. Global Mean is 4.35 ### Calculate user bias

tv_episode_df <- tv_episode_df %>%
  mutate(user_bias= user_avg - global_mean)
tv_episode_df
# A tibble: 30 × 5
# Groups:   user [5]
   user   tv_episodes     rating user_avg user_bias
   <chr>  <chr>            <int>    <dbl>     <dbl>
 1 Tenzin Squid Game           5      4.2   -0.150 
 2 Tenzin Emily in Paris       4      4.2   -0.150 
 3 Tenzin Ginny&Georgia        3      4.2   -0.150 
 4 Tenzin Brigerton            4      4.2   -0.150 
 5 Tenzin Wednesday            5      4.2   -0.150 
 6 Tenzin Stranger Things     NA      4.2   -0.150 
 7 Laura  Squid Game           4      4.4    0.0500
 8 Laura  Emily in Paris       5      4.4    0.0500
 9 Laura  Ginny&Georgia        4      4.4    0.0500
10 Laura  Brigerton            5      4.4    0.0500
# ℹ 20 more rows

Calculate Episode average and item bias

episode_average_df<-tv_episode_df %>%
  group_by(tv_episodes) %>%
  summarise(
    episode_avg = mean(rating, na.rm = TRUE)
  )%>%
      mutate(item_bias = episode_avg - global_mean)

episode_average_df
# A tibble: 6 × 3
  tv_episodes     episode_avg item_bias
  <chr>                 <dbl>     <dbl>
1 Brigerton              4       -0.350
2 Emily in Paris         4.75     0.400
3 Ginny&Georgia          3.75    -0.600
4 Squid Game             4.75     0.400
5 Stranger Things      NaN      NaN    
6 Wednesday              4.5      0.150

how Jose rate Squid Game?

squid_game_item_bias <- episode_average_df %>%
  filter(tv_episodes == "Squid Game") %>%
  pull(item_bias)
squid_game_item_bias
[1] 0.4

Squid Game’s rating relative to average is 0.4

jose_squid_game_user_bias <- tv_episode_df %>%
  filter(user == "Jose" & tv_episodes=="Squid Game") %>%
  pull(user_bias)
jose_squid_game_user_bias
[1] -0.1

Jose’s rating relative to average is -0.1

Calculate global baseline estimate

    global_baseline_estimate<-global_mean+squid_game_item_bias+jose_squid_game_user_bias
global_baseline_estimate
[1] 4.65

Conclusion

Based on the global baseline estimate recommendation system, Jose’s 4.65 rating for Squid Game stands out as a must-watch and highly recommended TV series.