We have completed the recommendations based on user similarity, and now you will learn how to implement the recommendations based on the item-based filtering methodology. We can implement the item-based CF method with some simple changes to the user-based filtering method.
In the item-based CF method, we identify the similarity between the items. Hence, while pivoting the dataset, we will pivot in such a way that the items become the column names and users become the row names so that we can compute the item similarity and also use the majority of the previous code with simple modifications. The following code can be used to pivot the dataset by making the items as the columns names:
library(data.table) pivoting <- data.table(rdata) pivotdataItem<-dcast.data.table(pivoting, UserID ~ Items, fun.aggregate=length, value.var="Items") colnames(pivotdataItem) write.csv(pivotdataItem, "Data/pivot-followsItem.csv") head(pivotdataItem)
The output of the preceding...