August 2018
Intermediate to advanced
378 pages
9h 9m
English
Here, we will see if we can build a deep learning model to beat the previous approach! The following code is in Chapter9/keras_recommend.R. The first part loads the dataset and creates new IDs for the customer and product codes. This is because Keras expects the indexes to be sequential, starting at zero, and unique:
library(readr)library(keras)set.seed(42)use_session_with_seed(42, disable_gpu = FALSE, disable_parallel_cpu = FALSE)df<-read_csv("recommend.csv")custs <- as.data.frame(unique(df$cust_id))custs$cust_id2 <- as.numeric(row.names(custs))colnames(custs) <- c("cust_id","cust_id2")custs$cust_id2 <- custs$cust_id2 - 1prods <- as.data.frame(unique(df$prod_id))prods$prod_id2 <- as.numeric(row.names(prods)) ...