Jean-Francois Leveque

Correction calcul précision et rappel

......@@ -16,12 +16,14 @@ public class PostprocessingExpert {
Set<Long> sampleItemIds;
Set<Long> recommendedItemIds;
Set<Long> sampleUserIds;
Set<Long> annotatedUserIds;
Map<Long, Set<Long>> sampleItemUserIds;
Map<Long, Integer> itemRecommandationUserCounts;
int recommendableItemCount;
int recommendedItemCount;
int recommendableItemUserCount;
int annotatedItemUserCount;
int recommendedItemAnnotatedUserCount;
int recommendedItemUserCount;
int validRecommendationCount;
double itemRecommandationUserCountRelativeStdDeviation;
......@@ -36,6 +38,7 @@ public class PostprocessingExpert {
public void analyze() {
analyzeSample();
analyzeAnnotated();
analyzeRecommendations();
}
......@@ -51,6 +54,19 @@ public class PostprocessingExpert {
return computePrecisionRecall();
}
protected void analyzeAnnotated() {
annotatedUserIds = new HashSet<>();
for (PostprocessingSample sample : annotatedList) {
Long userId = sample.getUserId();
annotatedUserIds.add(userId);
}
annotatedItemUserCount = annotatedList.size();
logger.debug("PR: Nombre d'associations annotées {}", annotatedItemUserCount);
}
protected void analyzeSample() {
sampleItemIds = new HashSet<>();
......@@ -90,8 +106,10 @@ public class PostprocessingExpert {
protected void analyzeRecommendations() {
recommendedItemUserCount = 0;
validRecommendationCount = 0;
recommendedItemAnnotatedUserCount = 0;
recommendedItemIds = new HashSet<>();
itemRecommandationUserCounts = new HashMap<>();
for (PostprocessingSample annote : annotatedList) {
logger.trace("Annotated item {}, user {}", annote.getItemId(), annote.getUserId());
}
......@@ -114,16 +132,18 @@ public class PostprocessingExpert {
}
}
logger.trace("Recommendation item {}, user {}", reco.getItemId(), reco.getUserId());
if (annotatedUserIds.contains(userId)) {
recommendedItemAnnotatedUserCount++;
}
if (annotatedList.contains(reco)) {
validRecommendationCount++;
}
}
recommendedItemCount = recommendedItemIds.size();
logger.debug("C: Nombre d'objets recommandés {}", recommendedItemCount);
logger.debug("C/PR: Nombre de couples item-user recommandés {}", recommendedItemUserCount);
annotatedItemUserCount = annotatedList.size();
logger.debug("PR: Nombre d'associations annotées {}", annotatedItemUserCount);
logger.debug("C: Nombre de couples item-user recommandés {}", recommendedItemUserCount);
logger.debug("PR: Nombre de recommandations annotées {}", validRecommendationCount);
logger.debug("PR: Nombre de couples item-user recommandés pour les users annotés {}", recommendedItemAnnotatedUserCount);
}
protected PostprocessingStatistics computeStatistics() {
......@@ -169,8 +189,8 @@ public class PostprocessingExpert {
float recall;
logger.debug("PR: nombre de recommandations annotées {}", validRecommendationCount);
logger.debug("PR: nombre de recommandations {}", recommendedItemUserCount);
precision = (float) validRecommendationCount / recommendedItemUserCount;
logger.debug("PR: nombre de recommandations pour utilisateurs annotés {}", recommendedItemAnnotatedUserCount);
precision = (float) validRecommendationCount / recommendedItemAnnotatedUserCount;
logger.debug("PR: précision {}", String.format(Locale.FRENCH, "%.3f", precision));
logger.debug("PR: nombre d'associations annotées {}", annotatedItemUserCount);
recall = (float) validRecommendationCount / annotatedItemUserCount;
......