这两个指标均为评估推荐列表质量的指标。
1. MAP(Mean Average Precision)
public double map(Triple[][] paraTrainingMatrix, Triple[][] paraTestingMatrix, int paraNumItems, int paraK) {
int[] rankList = new int[paraK];
int tempNumUsers = paraTrainingMatrix.length;
int groundTruthItem = 0;
double resultMap = 0;
double mapForEachUser = 0;
for (int i = 0; i < tempNumUsers; i++) {
mapForEachUser = 0;
if(paraTestingMatrix[i].length == 0) {
continue;
}//Of if
int numOfTestingItemsInRankList = 0;
for (int j = 0; j < paraTestingMatrix[i].length; j++) {
// an item in testing set is consider as the ground-truth item (gtItem).
groundTruthItem = paraTestingMatrix[i][j].item;
//computeRankList: compute a rank list for the gtItem.
//1. compute the predicted ratings for all items (donot exclude the items in the training set).
//2. compute the number of items whose predicted ratings above the gtItem.
//3. if the numbers is larger than paraK, the gtItem cannot rank in the Top-K;
// else output the rankList.
rankList = computeRankList(i, paraNumItems, paraK, groundTruthItem);
if (rankList == null) {
mapForEachUser += 0;
continue;
} // Of if
// find the ranking of the gtItem in the rankList and compute the precision.
for (int paraRank = 0; paraRank < rankList.length; paraRank++) {
if (groundTruthItem == rankList[paraRank]) {
numOfTestingItemsInRankList ++;
mapForEachUser += numOfTestingItemsInRankList / (paraRank + 1);
break;
} // Of if
} // Of for paraRank
} // Of for j
mapForEachUser /= paraTestingMatrix[i].length;
System.out.println("mapForEachUser" + mapForEachUser);
resultMap += mapForEachUser;
} // Of i
resultMap /= tempNumUsers;
return resultMap;
}// Of map
其中,为推荐列表的长度,为用户数目,为用户下标,为用户喜欢的物品集合与推荐列表的交集。
其中, 为用户数目, 为推荐列表的长度,为用户下标,为用户在测试集中的物品的集合。右侧的分式的含义是,对于推荐列表的第个物品如果在中,其Precision是:
分母是它的名次;
分子是排在该物品之前的物品中,有多少个属于。
2. NDCG(Normalized discounted cumulative gain)
分子:
其中,是中第个物品的实际评分,作为relevance。
分母:的计算式与相同。需要修改的是是将推荐列表的物品按照预测评分由高到低排序,即修改。的含义就是理想的,给出的本身就是按照预测评分由高到低排序,也希望该推荐列表能与用户实际的喜好一致。从而体现出,推荐列表的排序与用户真实喜好的关联性。