
com.shijingsh.ai.evaluate.ranking.MAPEvaluator Maven / Gradle / Ivy
The newest version!
package com.shijingsh.ai.evaluate.ranking;
import com.shijingsh.ai.evaluate.RankingEvaluator;
import com.shijingsh.ai.evaluate.RankingEvaluator;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntSet;
/**
* 平均准确率均值评估器
*
*
* MAP = Mean Average Precision
* https://en.wikipedia.org/wiki/Information_retrieval
* https://www.kaggle.com/wiki/MeanAveragePrecision
*
*
* @author Birdy
*/
public class MAPEvaluator extends RankingEvaluator {
public MAPEvaluator(int size) {
super(size);
}
@Override
protected float measure(IntSet checkCollection, IntList rankList) {
if (rankList.size() > size) {
rankList = rankList.subList(0, size);
}
int count = 0;
float map = 0F;
for (int index = 0; index < rankList.size(); index++) {
int itemIndex = rankList.get(index);
if (checkCollection.contains(itemIndex)) {
count++;
map += 1F * count / (index + 1);
}
}
return map / (checkCollection.size() < rankList.size() ? checkCollection.size() : rankList.size());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy