Jean-Francois Leveque

Analyse des recommandations et calcul de couverture.

...@@ -29,12 +29,18 @@ public class PostprocessingApplication { ...@@ -29,12 +29,18 @@ public class PostprocessingApplication {
29 String collectionSampleFilename; 29 String collectionSampleFilename;
30 @Value("${ratingSample.filename}") 30 @Value("${ratingSample.filename}")
31 String ratingSampleFilename; 31 String ratingSampleFilename;
32 + @Value("${recommandations.filename}")
33 + String recommandationsFilename;
32 String sampleFilename; 34 String sampleFilename;
33 Properties properties; 35 Properties properties;
34 Set<Long> sampleItemIds; 36 Set<Long> sampleItemIds;
37 + Set<Long> recommendedItemIds;
35 Set<Long> sampleUserIds; 38 Set<Long> sampleUserIds;
36 -
37 Map<Long, Set<Long>> sampleItemUserIds; 39 Map<Long, Set<Long>> sampleItemUserIds;
40 + int recommendableItemCount;
41 + int recommendedItemCount;
42 + int recommendableItemUserCount;
43 + int recommendedItemUserCount;
38 44
39 public static void main(String[] args) { 45 public static void main(String[] args) {
40 SpringApplication.run(PostprocessingApplication.class, args); 46 SpringApplication.run(PostprocessingApplication.class, args);
...@@ -49,6 +55,53 @@ public class PostprocessingApplication { ...@@ -49,6 +55,53 @@ public class PostprocessingApplication {
49 loadParametersProperties(); 55 loadParametersProperties();
50 loadSampleFilename(); 56 loadSampleFilename();
51 analyzeSample(); 57 analyzeSample();
58 + analyzeRecommendations();
59 + computeCoverage();
60 +
61 + }
62 +
63 + void computeCoverage() {
64 + float c1;
65 + float c2;
66 + int c3;
67 +
68 + logger.trace("Nombre d'objets recommandés {}", recommendedItemCount);
69 + logger.trace("Nombre d'objets recommandables {}", recommendableItemCount);
70 + c1 = (float) recommendedItemCount / recommendableItemCount;
71 + logger.trace("c1 {}", String.format("%.3f", c1));
72 + logger.trace("Nombre de couples item-user recommandés {}", recommendedItemUserCount);
73 + logger.trace("Nombre de couples item-user recommandables {}", recommendableItemUserCount);
74 + c2 = (float) recommendedItemUserCount / recommendableItemUserCount;
75 + logger.trace("c2 {}", String.format("%.3f", c2));
76 + c3 = recommendedItemCount;
77 + logger.trace("c3 {}", c3);
78 + }
79 +
80 + void analyzeRecommendations() {
81 + Reader in = null;
82 +
83 + try {
84 + recommendedItemUserCount = 0;
85 + recommendedItemIds = new HashSet<>();
86 + in = new InputStreamReader(new FileInputStream(dataDir + recommandationsFilename));
87 + Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
88 + for (CSVRecord record : records) {
89 + Long itemId = Long.parseLong(record.get("itemId"));
90 + Long userId = Long.parseLong(record.get("userId"));
91 + recommendedItemIds.add(itemId);
92 + if (sampleItemUserIds.containsKey(itemId)) {
93 + Set<Long> set = sampleItemUserIds.get(itemId);
94 + if (!set.contains(userId)) {
95 + recommendedItemUserCount++;
96 + }
97 + }
98 + }
99 + recommendedItemCount = recommendedItemIds.size();
100 + logger.trace("Nombre d'objets recommandés {}", recommendedItemCount);
101 + logger.trace("Nombre de couples item-user recommandés {}", recommendedItemUserCount);
102 + } catch (IOException e) {
103 + logger.error("analyzeRecommendations IOException : {}", e.getStackTrace());
104 + }
52 105
53 } 106 }
54 107
...@@ -59,8 +112,7 @@ public class PostprocessingApplication { ...@@ -59,8 +112,7 @@ public class PostprocessingApplication {
59 sampleItemIds = new HashSet<>(); 112 sampleItemIds = new HashSet<>();
60 sampleUserIds = new HashSet<>(); 113 sampleUserIds = new HashSet<>();
61 sampleItemUserIds = new HashMap<>(); 114 sampleItemUserIds = new HashMap<>();
62 - // 115 + in = new InputStreamReader(new FileInputStream(dataDir + sampleFilename));
63 - in = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(dataDir + sampleFilename));
64 Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in); 116 Iterable<CSVRecord> records = CSVFormat.TDF.withFirstRecordAsHeader().parse(in);
65 for (CSVRecord record : records) { 117 for (CSVRecord record : records) {
66 Long itemId = Long.parseLong(record.get("itemId")); 118 Long itemId = Long.parseLong(record.get("itemId"));
...@@ -77,7 +129,8 @@ public class PostprocessingApplication { ...@@ -77,7 +129,8 @@ public class PostprocessingApplication {
77 sampleItemUserIds.put(itemId, set); 129 sampleItemUserIds.put(itemId, set);
78 } 130 }
79 } 131 }
80 - logger.trace("Nombre d'objets recommandables {}", sampleItemIds.size()); 132 + recommendableItemCount = sampleItemIds.size();
133 + logger.trace("Nombre d'objets recommandables {}", recommendableItemCount);
81 logger.trace("Taille de la matrice item-user {}", sampleItemIds.size() * sampleUserIds.size()); 134 logger.trace("Taille de la matrice item-user {}", sampleItemIds.size() * sampleUserIds.size());
82 135
83 int sampleCoupleCount = 0; 136 int sampleCoupleCount = 0;
...@@ -85,8 +138,9 @@ public class PostprocessingApplication { ...@@ -85,8 +138,9 @@ public class PostprocessingApplication {
85 sampleCoupleCount += sampleItemUserIds.get(itemId).size(); 138 sampleCoupleCount += sampleItemUserIds.get(itemId).size();
86 } 139 }
87 140
141 + recommendableItemUserCount = sampleItemIds.size() * sampleUserIds.size() - sampleCoupleCount;
88 logger.trace("Nombre de couples item-user dans l'échantillon {}", sampleCoupleCount); 142 logger.trace("Nombre de couples item-user dans l'échantillon {}", sampleCoupleCount);
89 - logger.trace("Nombre de couples item-user recommandables {}", sampleItemIds.size() * sampleUserIds.size() - sampleCoupleCount); 143 + logger.trace("Nombre de couples item-user recommandables {}", recommendableItemUserCount);
90 144
91 } catch (IOException e) { 145 } catch (IOException e) {
92 logger.error("analyzeSample IOException : {}", e.getStackTrace()); 146 logger.error("analyzeSample IOException : {}", e.getStackTrace());
...@@ -114,12 +168,9 @@ public class PostprocessingApplication { ...@@ -114,12 +168,9 @@ public class PostprocessingApplication {
114 Properties properties = new Properties(); 168 Properties properties = new Properties();
115 InputStream in = null; 169 InputStream in = null;
116 try { 170 try {
117 - in = this.getClass().getClassLoader().getResourceAsStream(dataDir + parametersFilename); 171 + in = new FileInputStream(dataDir + parametersFilename);
118 -// in = new FileInputStream(dataDir + parametersFilename);
119 properties.load(in); 172 properties.load(in);
120 in.close(); 173 in.close();
121 - } catch (FileNotFoundException e) {
122 - logger.error("loadParametersProperties FileNotFoundException : {}", e.getStackTrace());
123 } catch (IOException e) { 174 } catch (IOException e) {
124 logger.error("loadParametersProperties IOException : {}", e.getStackTrace()); 175 logger.error("loadParametersProperties IOException : {}", e.getStackTrace());
125 } 176 }
......