Global Baseline Estimates
To create a global baseline estimate recommendation system for this
lab first requires taking my tables from of movie ratings from my
previous lab. For the purposes of this lab I will rejoin the User, Movie
and Ratings tables to match the given example. Where my lab 2 left off,
every row was a different critic and their rating of that specific
movie. It will be necessary to have my table have each critic and every
other column be a movie that they rated. This puts all of a user’s
ratings in one clean row. To accomplish I will have to adjust how I
joined these 3 tables together. Once my tables are set up, I can then
becgin to run calculations for the other columns and rows like the user
average, the movie average rating, as the example shows. To figure out
what each column performed these calculations I imported the examples in
Google Sheets and then double clicked these boxes to see how the value
was obtained. Using this method, I believe that once setup, this lab
will be fairly straightforward to accomplish. One thing I am confused
about is calculating the deviations (as seen in the Movie Centered
Ratings tab). These values don’t seem to be used in any of the final
processes of calulating a recommendation for a user. However, maybe this
is an oversight on my part, and I missed something when researching how
to solve create this recommendation model. I will update any changes to
my ideas in my Conclusion.
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
library(dplyr)
users_df <- read.csv("https://raw.githubusercontent.com/Renagade316/DATA607-Labs/refs/heads/main/Lab2/Lab2A/Lab2a_Users.csv")
movies_df <- read.csv("https://raw.githubusercontent.com/Renagade316/DATA607-Labs/refs/heads/main/Lab2/Lab2A/Lab2a_Movies.csv")
ratings_df <- read.csv("https://raw.githubusercontent.com/Renagade316/DATA607-Labs/refs/heads/main/Lab2/Lab2A/Lab2a_Ratings.csv")
glimpse(users_df)
## Rows: 5
## Columns: 2
## $ X1 <int> 2, 3, 4, 5, 6
## $ Elvy <chr> "Chrissie", "Kaitlin", "Renan", "Jackson", "Isaiah"
colnames(users_df)[1] <- "user_id"
colnames(users_df)[2] <- "name"
glimpse(movies_df)
## Rows: 5
## Columns: 2
## $ X1 <int> 2, 3, 4, 5, 6
## $ The.Odyssey <chr> "Avatar Fire and Ash", "Obsession", "Weapons", "The Long W…
colnames(movies_df)[1] <- "movie_id"
colnames(movies_df)[2] <- "title"
glimpse(ratings_df)
## Rows: 23
## Columns: 3
## $ X1 <int> 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 6,…
## $ X1.1 <int> 2, 3, 4, 5, 6, 1, 2, 3, 6, 1, 4, 1, 3, 4, 6, 1, 6, 1, 2, 3, 4, 5,…
## $ X4 <int> 3, 5, 4, 5, 5, 5, 5, 4, 4, 5, 4, 5, 5, 3, 4, 5, 5, 5, 3, 5, 5, 4,…
colnames(ratings_df)[1] <- "user_id"
colnames(ratings_df)[2] <- "movie_id"
colnames(ratings_df)[3] <- "rating"
joined_table <- left_join(users_df, ratings_df, by = "user_id")
joined_table <- left_join(movies_df, joined_table, by = "movie_id")
joined_table <- select(joined_table, name, title, rating)
# Turning the table from long to wide
movie_ratings <- joined_table |> pivot_wider(names_from = title, values_from = rating)
#User ratings
movie_ratings <- movie_ratings |> mutate(
user_avg =
rowMeans(pick
(
`Avatar Fire and Ash`,
`Obsession`,
`Weapons`,
`The Long Walk`,
`Spiderman Brand New Day`
), na.rm = TRUE))
#Movie Ratings
movie_ratings <- movie_ratings |>
add_row(
name = 'movie_avg',
'Avatar Fire and Ash' = mean(movie_ratings$`Avatar Fire and Ash`, na.rm = TRUE),
'Obsession' = mean(movie_ratings$Obsession, na.rm = TRUE),
'Weapons' = mean(movie_ratings$Weapons, na.rm = TRUE),
'The Long Walk' = mean(movie_ratings$`The Long Walk`, na.rm = TRUE),
'Spiderman Brand New Day' = mean(movie_ratings$`Spiderman Brand New Day`, na.rm = TRUE),
'user_avg' = mean(movie_ratings$user_avg, na.rm = TRUE)
)
#Movie Ratings - Mean Movie
movie_ratings <- movie_ratings |>
mutate(
user_avg_sub_mean_movie = movie_ratings$user_avg - movie_ratings$user_avg[6]
#if_else(movie_ratings$user_avg - movie_ratings$user_avg[6] == 0,
# user_avg_sub_mean_movie = movie_ratings$user_avg - movie_ratings$user_avg[6],
# user_avg_sub_mean_movie == " ")
)
#Movie_Avg - Mean_movie
movie_ratings <- movie_ratings |>
add_row(
name = 'movie_avg-mean_movie',
'Avatar Fire and Ash' = movie_ratings$`Avatar Fire and Ash`[6] - movie_ratings$user_avg[6],
'Obsession' = movie_ratings$`Obsession`[6] - movie_ratings$user_avg[6],
'Weapons' = movie_ratings$`Weapons`[6] - movie_ratings$user_avg[6],
'The Long Walk' = movie_ratings$`The Long Walk`[6] - movie_ratings$user_avg[6],
'Spiderman Brand New Day' = movie_ratings$`Spiderman Brand New Day`[6] - movie_ratings$user_avg[6]
)
movie_ratings
## # A tibble: 7 × 8
## name `Avatar Fire and Ash` Obsession Weapons `The Long Walk`
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Chrissie 5 4 NA NA
## 2 Isaiah 3 5 5 4
## 3 Renan NA 5 3 NA
## 4 Kaitlin NA NA 4 NA
## 5 Jackson NA NA NA NA
## 6 movie_avg 4 4.67 4 4
## 7 movie_avg-mean_movie -0.307 0.360 -0.307 -0.307
## # ℹ 3 more variables: `Spiderman Brand New Day` <dbl>, user_avg <dbl>,
## # user_avg_sub_mean_movie <dbl>
#Global Baseline Estimate = Mean Movie Rating + Movie_Name's rating relative to average + User's rating relative to average
#Global Baseline Estimate for each movie Kaitlin hasn't seen
avatar_gbe <- movie_ratings$user_avg[6] - movie_ratings$`Avatar Fire and Ash`[7]- movie_ratings$user_avg_sub_mean_movie[4]
avatar_gbe
## [1] 4.92
obsession_gbe <- movie_ratings$user_avg[6] - movie_ratings$`Obsession`[7]- movie_ratings$user_avg_sub_mean_movie[4]
obsession_gbe
## [1] 4.253333
lwalk_gbe <- movie_ratings$user_avg[6] - movie_ratings$`The Long Walk`[7]- movie_ratings$user_avg_sub_mean_movie[4]
lwalk_gbe
## [1] 4.92
spiderman_gbe <- movie_ratings$user_avg[6] - movie_ratings$`Spiderman Brand New Day`[7]- movie_ratings$user_avg_sub_mean_movie[4]
spiderman_gbe
## [1] 4.67
Based on Global Baseline Estimates, Kaitlin should watch either Avatar Fire and Ash or The Long Walk.
To conclude, many of my predictions in the introduction were accurate. However, I can say I now understood the value of the user_avg - mean movie column, I did not realize that it was used in the final equation at the end. Also, I did have some trouble figuring out how I would rearrange the data so that it was more wide than long, I stumble upon the pivot_wider() function which made it simple to create columns based on the movie titles and populate each cell with the rating from that particular user. If I wanted to expand this project, I would create another column and put the title of the title of the movie with the highest Global Baseline Estimate score, so that in the real world, the user would be offered a movie as a recommendation. This would be done, by comparing the values of each Global Baseline Estimate value for each movie. I also would wonder about scaleability because many of these values are calculated based on the positional index of a specific cell, which would make this difficult, if there were more values being added to the data set.