0

I have the following code:

testset2 <- testset %>%
  left_join(movie_dev, by="movieId") %>%
  left_join(user_dev, by="userId") %>%
  mutate(prediction = naive + ifelse(is.na(testset$movieid_dev),0,testset$movieid_dev)  +ifelse(is.na(testset$userid_dev),0,testset$userid_dev)) 

When I explore the df, most of the prediction column is working perfectly. But it will work only for cases (movieid and userid) already known by the training_set. For all other unknown cases, prediction variable should only consider the naive object (a constant) and insert zero for unknown movieid and userids. But instead, I'm getting NAs. What should I do?

  • Hi Valdir, welcome to SO, could you please provide a reprex, look into dput – Bruno Jun 07 '20 at 19:59
  • The `tidyverse` package has a `replace_na` function that you can replace na with zero. – at80 Jun 07 '20 at 20:14
  • Thanks, Bruno! I have already tried replace_na but unsuccessfully. At last, I tried the following: testset$movieid_dev[is.na(testset$movieid_dev)] <- 0 and it worked! – ValdirSantos Jun 07 '20 at 21:16

0 Answers0