Commit 23c96b0a349ed667eb384f5293d18a1735264a5e
1 parent
67cefa3d
Exists in
master
and in
1 other branch
Minor fix.
Showing
2 changed files
with
16 additions
and
12 deletions
Show diff stats
src/bin/cross_validation.py
| @@ -27,7 +27,7 @@ import logging | @@ -27,7 +27,7 @@ import logging | ||
| 27 | import datetime | 27 | import datetime |
| 28 | 28 | ||
| 29 | from config import Config | 29 | from config import Config |
| 30 | -from evaluation import CrossValidation, Precision, Recall, F1, Accuracy, SimpleAccuracy | 30 | +from evaluation import CrossValidation, Precision, Recall, F_score, FPR, Accuracy |
| 31 | from recommender import Recommender | 31 | from recommender import Recommender |
| 32 | from user import RandomPopcon,LocalSystem,PopconSystem | 32 | from user import RandomPopcon,LocalSystem,PopconSystem |
| 33 | 33 | ||
| @@ -45,10 +45,10 @@ if __name__ == '__main__': | @@ -45,10 +45,10 @@ if __name__ == '__main__': | ||
| 45 | metrics = [] | 45 | metrics = [] |
| 46 | metrics.append(Precision()) | 46 | metrics.append(Precision()) |
| 47 | metrics.append(Recall()) | 47 | metrics.append(Recall()) |
| 48 | - metrics.append(F1()) | 48 | + metrics.append(F_score(0.5)) |
| 49 | metrics.append(Accuracy()) | 49 | metrics.append(Accuracy()) |
| 50 | - metrics.append(SimpleAccuracy()) | ||
| 51 | - validation = CrossValidation(0.9,10,rec,metrics,0.005) | 50 | + metrics.append(FPR()) |
| 51 | + validation = CrossValidation(0.9,10,rec,metrics,1) | ||
| 52 | validation.run(user) | 52 | validation.run(user) |
| 53 | print validation | 53 | print validation |
| 54 | 54 |
src/evaluation.py
| @@ -137,7 +137,8 @@ class FPR(Metric): | @@ -137,7 +137,8 @@ class FPR(Metric): | ||
| 137 | """ | 137 | """ |
| 138 | Compute metric. | 138 | Compute metric. |
| 139 | """ | 139 | """ |
| 140 | - return float(len(evaluation.false_positive))/evaluation.true_negatives_len | 140 | + return (float(len(evaluation.false_positive))/ |
| 141 | + evaluation.real_negative_len) | ||
| 141 | 142 | ||
| 142 | class F_score(Metric): | 143 | class F_score(Metric): |
| 143 | """ | 144 | """ |
| @@ -148,7 +149,7 @@ class F_score(Metric): | @@ -148,7 +149,7 @@ class F_score(Metric): | ||
| 148 | """ | 149 | """ |
| 149 | Set metric description. | 150 | Set metric description. |
| 150 | """ | 151 | """ |
| 151 | - self.desc = " F_score " | 152 | + self.desc = " F(%.1f) " % k |
| 152 | self.k = k | 153 | self.k = k |
| 153 | 154 | ||
| 154 | def run(self,evaluation): | 155 | def run(self,evaluation): |
| @@ -254,12 +255,15 @@ class Evaluation: | @@ -254,12 +255,15 @@ class Evaluation: | ||
| 254 | self.false_negative = [v[0] for v in self.real_relevant if not v[0] in | 255 | self.false_negative = [v[0] for v in self.real_relevant if not v[0] in |
| 255 | [w[0] for w in self.predicted_relevant]] | 256 | [w[0] for w in self.predicted_relevant]] |
| 256 | 257 | ||
| 257 | - self.true_negatives_len = self.repository_size - len(self.real_relevant) | ||
| 258 | - #logging.debug("TP: %d" % len(self.true_positive)) | ||
| 259 | - #logging.debug("FP: %d" % len(self.false_positive)) | ||
| 260 | - #logging.debug("FN: %d" % len(self.false_negative)) | ||
| 261 | - #logging.debug("Repo_size: %d" % self.repository_size) | ||
| 262 | - #logging.debug("Relevant: %d" % len(self.real_relevant)) | 258 | + self.real_negative_len = self.repository_size-len(self.real_relevant) |
| 259 | + self.true_negative_len = (self.real_negative_len-len(self.false_positive)) | ||
| 260 | + logging.debug("TP: %d" % len(self.true_positive)) | ||
| 261 | + logging.debug("FP: %d" % len(self.false_positive)) | ||
| 262 | + logging.debug("FN: %d" % len(self.false_negative)) | ||
| 263 | + logging.debug("TN: %d" % self.true_negative_len) | ||
| 264 | + logging.debug("Repo_size: %d" % self.repository_size) | ||
| 265 | + logging.debug("Relevant: %d" % len(self.real_relevant)) | ||
| 266 | + logging.debug("Irrelevant: %d" % self.real_negative_len) | ||
| 263 | 267 | ||
| 264 | def run(self,metric): | 268 | def run(self,metric): |
| 265 | """ | 269 | """ |