Jean-Francois Leveque

Analyse des recommandations et calcul de couverture.

......@@ -29,12 +29,18 @@ public class PostprocessingApplication {
String collectionSampleFilename;
@Value("${ratingSample.filename}")
String ratingSampleFilename;
@Value("${recommandations.filename}")
String recommandationsFilename;
String sampleFilename;
Properties properties;
Set<Long> sampleItemIds;
Set<Long> recommendedItemIds;
Set<Long> sampleUserIds;
Map<Long, Set<Long>> sampleItemUserIds;
int recommendableItemCount;
int recommendedItemCount;
int recommendableItemUserCount;
int recommendedItemUserCount;
public static void main(String[] args) {
SpringApplication.run(PostprocessingApplication.class, args);
......@@ -49,6 +55,53 @@ public class PostprocessingApplication {
loadParametersProperties();
loadSampleFilename();
analyzeSample();
analyzeRecommendations();
computeCoverage();
}
void computeCoverage() {
float c1;
float c2;
int c3;
logger.trace("Nombre d'objets recommandés {}", recommendedItemCount);
logger.trace("Nombre d'objets recommandables {}", recommendableItemCount);
c1 = (float) recommendedItemCount / recommendableItemCount;
logger.trace("c1 {}", String.format("%.3f", c1));
logger.trace("Nombre de couples item-user recommandés {}", recommendedItemUserCount);
logger.trace("Nombre de couples item-user recommandables {}", recommendableItemUserCount);
c2 = (float) recommendedItemUserCount / recommendableItemUserCount;
logger.trace("c2 {}", String.format("%.3f", c2));
c3 = recommendedItemCount;
logger.trace("c3 {}", c3);
}
void analyzeRecommendations() {
Reader in = null;
try {
recommendedItemUserCount = 0;
recommendedItemIds = new HashSet<>();
in = new InputStreamReader(new FileInputStream(dataDir + recommandationsFilename));
Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
for (CSVRecord record : records) {
Long itemId = Long.parseLong(record.get("itemId"));
Long userId = Long.parseLong(record.get("userId"));
recommendedItemIds.add(itemId);
if (sampleItemUserIds.containsKey(itemId)) {
Set<Long> set = sampleItemUserIds.get(itemId);
if (!set.contains(userId)) {
recommendedItemUserCount++;
}
}
}
recommendedItemCount = recommendedItemIds.size();
logger.trace("Nombre d'objets recommandés {}", recommendedItemCount);
logger.trace("Nombre de couples item-user recommandés {}", recommendedItemUserCount);
} catch (IOException e) {
logger.error("analyzeRecommendations IOException : {}", e.getStackTrace());
}
}
......@@ -59,8 +112,7 @@ public class PostprocessingApplication {
sampleItemIds = new HashSet<>();
sampleUserIds = new HashSet<>();
sampleItemUserIds = new HashMap<>();
//
in = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(dataDir + sampleFilename));
in = new InputStreamReader(new FileInputStream(dataDir + sampleFilename));
Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
for (CSVRecord record : records) {
Long itemId = Long.parseLong(record.get("itemId"));
......@@ -77,7 +129,8 @@ public class PostprocessingApplication {
sampleItemUserIds.put(itemId, set);
}
}
logger.trace("Nombre d'objets recommandables {}", sampleItemIds.size());
recommendableItemCount = sampleItemIds.size();
logger.trace("Nombre d'objets recommandables {}", recommendableItemCount);
logger.trace("Taille de la matrice item-user {}", sampleItemIds.size() * sampleUserIds.size());
int sampleCoupleCount = 0;
......@@ -85,8 +138,9 @@ public class PostprocessingApplication {
sampleCoupleCount += sampleItemUserIds.get(itemId).size();
}
recommendableItemUserCount = sampleItemIds.size() * sampleUserIds.size() - sampleCoupleCount;
logger.trace("Nombre de couples item-user dans l'échantillon {}", sampleCoupleCount);
logger.trace("Nombre de couples item-user recommandables {}", sampleItemIds.size() * sampleUserIds.size() - sampleCoupleCount);
logger.trace("Nombre de couples item-user recommandables {}", recommendableItemUserCount);
} catch (IOException e) {
logger.error("analyzeSample IOException : {}", e.getStackTrace());
......@@ -114,12 +168,9 @@ public class PostprocessingApplication {
Properties properties = new Properties();
InputStream in = null;
try {
in = this.getClass().getClassLoader().getResourceAsStream(dataDir + parametersFilename);
// in = new FileInputStream(dataDir + parametersFilename);
in = new FileInputStream(dataDir + parametersFilename);
properties.load(in);
in.close();
} catch (FileNotFoundException e) {
logger.error("loadParametersProperties FileNotFoundException : {}", e.getStackTrace());
} catch (IOException e) {
logger.error("loadParametersProperties IOException : {}", e.getStackTrace());
}
......