0

In this code:-

top10_prediction_linear <- test_set %>%
  left_join(b_i, by = "movieId") %>%
  left_join(b_u, by = "userId") %>%
  mutate(y_hat = mu + b_i + b_u) %>%
  arrange(desc(y_hat)) %>%
  select(title) %>%
  unique() %>%
  slice_head(n = 10)
top10_prediction_linear_df <- data.frame(Title = top10_prediction_linear,
                                         Rating = rep(NA, 10), 
                                         Count = rep(NA, 10))

for (i in 1:10) {
  indexes <- which(test_set$title == as.character(top10_prediction_linear[i]))
  top10_prediction_linear_df$Rating[i] <- mean(test_set$rating[indexes])
  top10_prediction_linear_df$Count[i] <- sum(
    test_set$title == as.character(top10_prediction_linear[i])
  )
}
print(top10_prediction_linear_df)

I got this error:-

Error in UseMethod("left_join") : no applicable method for 'left_join' applied to an object of class "c('matrix', 'array', 'integer', 'numeric')"

Help me to remove this error and run my code

bretauv
  • 7,756
  • 2
  • 20
  • 57
  • 1
    One of your inputs looks to be a `matrix`, not a `data.frame` or `tibble` as required. Check each of your `test_set`, `b_i` and `b_u` objects for what they are, and possibly wrap them in `as.data.frame`. – thelatemail Apr 11 '23 at 00:02
  • Hello, your example is not reproducible: you don't provide example data and don't specify the packages you use. See [the FAQ](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) or the [`reprex` package](https://reprex.tidyverse.org/) – bretauv Apr 11 '23 at 08:36

0 Answers0