This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readr) | |
library(dplyr) | |
url <- "https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv" | |
df <- | |
read_delim(url, delim = ";") %>% | |
dplyr::mutate(taste = as.factor(ifelse(quality < 6, "bad", ifelse(quality > 6, "good", "average")))) %>% | |
dplyr::select(-quality) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_recommendation_ratings <- function(rating_file_path) { | |
# Read user ID, item ID, user preference CSV data | |
ratings <- read.csv(file = rating_file_path, header = FALSE, col.names = c('user', 'item', 'preference')) | |
# Create item co-occurrence matrix | |
co_occurrence_matrix <- crossprod(table(ratings[, c('user', 'item')])) | |
# Convert long format to wide format and replace NAs with 0s | |
user_ratings <- tidyr::spread(ratings, user, preference, fill = 0) | |