Commit c20a2199d79b5108f5aab76e981c9ba87c940f01
1 parent
100c5082
Exists in
master
and in
1 other branch
Fixed bug with sample randomless.
Showing
1 changed file
with
10 additions
and
12 deletions
Show diff stats
src/experiments/runner.py
... | ... | @@ -74,12 +74,13 @@ class ContentBasedSuite(expsuite.PyExperimentSuite): |
74 | 74 | |
75 | 75 | def iterate(self, params, rep, n): |
76 | 76 | if params['name'].startswith("content"): |
77 | - # Get full recommendation | |
78 | 77 | item_score = dict.fromkeys(self.user.pkg_profile,1) |
78 | + # Prepare partition | |
79 | 79 | sample = {} |
80 | 80 | for i in range(self.sample_size): |
81 | - item, score = item_score.popitem() | |
82 | - sample[item] = score | |
81 | + key = random.choice(item_score.keys()) | |
82 | + sample[key] = item_score.pop(key) | |
83 | + # Get full recommendation | |
83 | 84 | user = User(item_score) |
84 | 85 | recommendation = self.rec.get_recommendation(user,self.repo_size) |
85 | 86 | # Write recall log |
... | ... | @@ -106,13 +107,13 @@ class ContentBasedSuite(expsuite.PyExperimentSuite): |
106 | 107 | output.write(pkg+"\n") |
107 | 108 | output.close() |
108 | 109 | # Plot metrics summary |
109 | - g = Gnuplot.Gnuplot() | |
110 | - g('set style data lines') | |
111 | - g.xlabel('Recommendation size') | |
112 | 110 | accuracy = [] |
113 | 111 | precision = [] |
114 | 112 | recall = [] |
115 | 113 | f1 = [] |
114 | + g = Gnuplot.Gnuplot() | |
115 | + g('set style data lines') | |
116 | + g.xlabel('Recommendation size') | |
116 | 117 | for size in range(1,len(recommendation.ranking)+1,100): |
117 | 118 | predicted = RecommendationResult(dict.fromkeys(recommendation.ranking[:size],1)) |
118 | 119 | real = RecommendationResult(sample) |
... | ... | @@ -121,17 +122,14 @@ class ContentBasedSuite(expsuite.PyExperimentSuite): |
121 | 122 | precision.append([size,evaluation.run(Precision())]) |
122 | 123 | recall.append([size,evaluation.run(Recall())]) |
123 | 124 | f1.append([size,evaluation.run(F1())]) |
124 | - #print "accuracy", len(accuracy) | |
125 | - #print "precision", len(precision) | |
126 | - #print "recall", len(recall) | |
127 | - #print "f1", len(f1) | |
128 | 125 | g.plot(Gnuplot.Data(accuracy,title="Accuracy"), |
129 | 126 | Gnuplot.Data(precision,title="Precision"), |
130 | 127 | Gnuplot.Data(recall,title="Recall"), |
131 | 128 | Gnuplot.Data(f1,title="F1")) |
132 | 129 | g.hardcopy(recall_file+"-plot.ps", enhanced=1, color=1) |
133 | - result = {} | |
134 | - result = {'weight': params['weight'], | |
130 | + # Iteration log | |
131 | + result = {'iteration': n, | |
132 | + 'weight': params['weight'], | |
135 | 133 | 'strategy': params['strategy'], |
136 | 134 | 'accuracy': accuracy[20], |
137 | 135 | 'precision': precision[20], | ... | ... |