Skip to content

Commit

Permalink
Store the rating matrix in the sparse mode
Browse files Browse the repository at this point in the history
  • Loading branch information
statwangz committed Sep 19, 2023
1 parent a7a641c commit 737e59d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions data-raw/ml100k.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ N <- (range(u_data[, 1]))[2]
# Movie, range(u_data[, 2])
M <- (range(u_data[, 2]))[2]

u_data_matrix <- matrix(NA, N, M)
for (i in seq_len(dim(u_data)[1])) {
u_data_matrix[u_data[i, 1], u_data[i, 2]] <- u_data[i, 3]
}
u_data_matrix <- Matrix::sparseMatrix(
i = u_data[, 1], j = u_data[, 2],
x = u_data[, 3],
dims = c(N, M),
symmetric = FALSE, triangular = FALSE,
index1 = TRUE,
repr = "C"
)
# head(u_data_matrix)

## User information
Expand Down Expand Up @@ -51,7 +55,13 @@ u_item <- read.csv(
# all_genres

u_item <- u_item[, c(6:24)]
colnames(u_item) <- c("Unknown", "Action", "Adventure", "Animation", "Children‘s", "Comedy", "Crime", "Documentary", "Drama", "Fantasy", "Film-Noir", "Horror", "Musical", "Mystery", "Romance", "Sci-Fi", "Thriller", "War", "Western")
colnames(u_item) <- c(
"Unknown", "Action", "Adventure", "Animation",
"Children‘s", "Comedy", "Crime", "Documentary",
"Drama", "Fantasy", "Film-Noir", "Horror",
"Musical", "Mystery", "Romance", "Sci-Fi",
"Thriller", "War", "Western"
)
# head(u_item)
# dim(u_item)

Expand Down

0 comments on commit 737e59d

Please sign in to comment.