O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Optimizing parameters

Once we have identified our best model, the next step would be to optimize this model. Every recommendation model contains some parameters--numeric or categorical. For instance, IBCF takes account of the k-closest items, but how can we optimize the value of k?

  1. Instead of specifying a single value while evaluating the model, we can specify a range of values for the parameter and then evaluate the model to find out the optimal value for this parameter:
> vector_k <- c(5, 10, 20, 30, 40) 
> models_to_evaluate <- lapply(vector_k, function(k){ 
  list(name = "IBCF", param = list(method = "cosine", k = k)) 
}) 
> names(models_to_evaluate) <- paste0("IBCF_k_", vector_k)
  1. Now visualize the best performing k with ROC curve:
> plot(list_results, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required