我正在尝试测试我使用recommenderlab
包创建的二进制推荐系统。当我运行calcPredictionAccuracy
函数时,我收到以下错误:
.local(x,data,...)出错: 您需要指定预测的项目数量! 我已经进行了大量搜索,似乎无法找到解决此问题的方法。如果我尝试添加给定的参数,则错误更改为:
error.ubcf< -calcPredictionAccuracy(p.ubcf,getData(test_index," unknown",given = 3)) .local(x,...)出错:未使用的参数(给定= 3)
以下是我的代码的快速浏览:
我的数据集是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")
这会产生以下错误:
error.ubcf&lt; -calcPredictionAccuracy(p.ubcf,getData(test_index,&#34; unknown&#34;)) .local(x,data,...)出错: 您需要指定预测的项目数量!
我的问题是,在我的代码中,我必须指定为预测提供多少项?这个问题是否与我的数据是二进制有关?
由于
罗伯特答案 0 :(得分:0)
对于topNList,您必须指定要返回的项目数。所以你用predict()函数调用添加这些:
# 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)
通过改变n,您将能够看到它如何影响您的TP / FP / TN / FN精度测量以及精确/召回。这些值的计算方法位于此页面的底部: https://github.com/mhahsler/recommenderlab/blob/master/R/calcPredictionAccuracy.R