Reputation: 3
I am trying to test a binary recommendation systems I created with the recommenderlab
package. When I run the calcPredictionAccuracy
function I get the following error:
Error in .local(x, data, ...) : You need to specify how many items were given for the prediction! I have performed numerous searches and can't seem to find any solution to this issue. If I try to add the given argument the error changes to:
error.ubcf<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown", given=3)) Error in .local(x, ...) : unused argument (given = 3)
Here is a quick look at my code:
my data set is binary.watch.ratings
affinity.matrix <- as(binary.watch.ratings,"binaryRatingMatrix")
test_index <- evaluationScheme(affinity.matrix[1:1000], method="split",
train=0.9, given=1)
# creation of recommender model based on ubcf
Rec.ubcf <- Recommender(getData(test_index, "train"), "UBCF")
# creation of recommender model based on ibcf for comparison
Rec.ibcf <- Recommender(getData(test_index, "train"), "IBCF")
# making predictions on the test data set
p.ubcf <- predict(Rec.ubcf, getData(test_index, "known"), type="topNList")
# making predictions on the test data set
p.ibcf <- predict(Rec.ibcf, getData(test_index, "known"), type="topNList")
# obtaining the error metrics for both approaches and comparing them
##error occurs with the following two lines
error.ubcf<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown"))
error.ibcf<-calcPredictionAccuracy(p.ibcf, getData(test_index, "unknown"))
error <- rbind(error.ubcf,error.ibcf)
rownames(error) <- c("UBCF","IBCF")
This produces the following error:
error.ubcf<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown")) Error in .local(x, data, ...) : You need to specify how many items were given for the prediction!
My question is what point in my code must I specify how many items are given for prediction? Is this issue related to the fact that my data is binary?
Thanks
Robert
Upvotes: 0
Views: 677
Reputation: 121
for topNList, you must specify the number of items you want back. So you add these with the predict() function call:
# making predictions on the test data set
p.ubcf <- predict(Rec.ubcf, getData(test_index, "known"), type="topNList", n=10)
# making predictions on the test data set
p.ibcf <- predict(Rec.ibcf, getData(test_index, "known"), type="topNList", n=10)
By varying n, you will be able to see how it impacts your TP/FP/TN/FN accuracy measures, as well as precision/recall. The calculation methodology for these values is at the bottom of this page: https://github.com/mhahsler/recommenderlab/blob/master/R/calcPredictionAccuracy.R
Upvotes: 0