测试推荐系统:如何指定为预测提供了多少项目。 `calcPredictionAccuracy` 函数
Testing Recommendation systems: How to specify how many items were given for the prediction. `calcPredictionAccuracy` function
我正在尝试测试我使用 recommenderlab
包创建的二进制推荐系统。当我 运行 calcPredictionAccuracy
函数时,出现以下错误:
.local(x, data, ...) 错误:
您需要指定为预测提供了多少项目!
我进行了大量搜索,但似乎找不到解决此问题的方法。如果我尝试添加给定的参数,错误将更改为:
error.ubcf<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown", given=3))
Error in .local(x, ...) : unused argument (given = 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<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown"))
Error in .local(x, data, ...) :
You need to specify how many items were given for the prediction!
我的问题是我必须在我的代码中的哪一点指定要预测多少项目?这个问题与我的数据是二进制的事实有关吗?
谢谢
罗伯特
对于 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 准确度测量以及 precision/recall。这些值的计算方法位于本页底部:
https://github.com/mhahsler/recommenderlab/blob/master/R/calcPredictionAccuracy.R
我正在尝试测试我使用 recommenderlab
包创建的二进制推荐系统。当我 运行 calcPredictionAccuracy
函数时,出现以下错误:
.local(x, data, ...) 错误: 您需要指定为预测提供了多少项目! 我进行了大量搜索,但似乎找不到解决此问题的方法。如果我尝试添加给定的参数,错误将更改为:
error.ubcf<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown", given=3)) Error in .local(x, ...) : unused argument (given = 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<-calcPredictionAccuracy(p.ubcf, getData(test_index, "unknown")) Error in .local(x, data, ...) : You need to specify how many items were given for the prediction!
我的问题是我必须在我的代码中的哪一点指定要预测多少项目?这个问题与我的数据是二进制的事实有关吗?
谢谢
罗伯特
对于 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 准确度测量以及 precision/recall。这些值的计算方法位于本页底部: https://github.com/mhahsler/recommenderlab/blob/master/R/calcPredictionAccuracy.R