Commit c20a2199d79b5108f5aab76e981c9ba87c940f01

Authored by Tássia Camões Araújo
1 parent 100c5082
Exists in master and in 1 other branch add_vagrant

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,12 +74,13 @@ class ContentBasedSuite(expsuite.PyExperimentSuite):
74 74
75 def iterate(self, params, rep, n): 75 def iterate(self, params, rep, n):
76 if params['name'].startswith("content"): 76 if params['name'].startswith("content"):
77 - # Get full recommendation  
78 item_score = dict.fromkeys(self.user.pkg_profile,1) 77 item_score = dict.fromkeys(self.user.pkg_profile,1)
  78 + # Prepare partition
79 sample = {} 79 sample = {}
80 for i in range(self.sample_size): 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 user = User(item_score) 84 user = User(item_score)
84 recommendation = self.rec.get_recommendation(user,self.repo_size) 85 recommendation = self.rec.get_recommendation(user,self.repo_size)
85 # Write recall log 86 # Write recall log
@@ -106,13 +107,13 @@ class ContentBasedSuite(expsuite.PyExperimentSuite): @@ -106,13 +107,13 @@ class ContentBasedSuite(expsuite.PyExperimentSuite):
106 output.write(pkg+"\n") 107 output.write(pkg+"\n")
107 output.close() 108 output.close()
108 # Plot metrics summary 109 # Plot metrics summary
109 - g = Gnuplot.Gnuplot()  
110 - g('set style data lines')  
111 - g.xlabel('Recommendation size')  
112 accuracy = [] 110 accuracy = []
113 precision = [] 111 precision = []
114 recall = [] 112 recall = []
115 f1 = [] 113 f1 = []
  114 + g = Gnuplot.Gnuplot()
  115 + g('set style data lines')
  116 + g.xlabel('Recommendation size')
116 for size in range(1,len(recommendation.ranking)+1,100): 117 for size in range(1,len(recommendation.ranking)+1,100):
117 predicted = RecommendationResult(dict.fromkeys(recommendation.ranking[:size],1)) 118 predicted = RecommendationResult(dict.fromkeys(recommendation.ranking[:size],1))
118 real = RecommendationResult(sample) 119 real = RecommendationResult(sample)
@@ -121,17 +122,14 @@ class ContentBasedSuite(expsuite.PyExperimentSuite): @@ -121,17 +122,14 @@ class ContentBasedSuite(expsuite.PyExperimentSuite):
121 precision.append([size,evaluation.run(Precision())]) 122 precision.append([size,evaluation.run(Precision())])
122 recall.append([size,evaluation.run(Recall())]) 123 recall.append([size,evaluation.run(Recall())])
123 f1.append([size,evaluation.run(F1())]) 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 g.plot(Gnuplot.Data(accuracy,title="Accuracy"), 125 g.plot(Gnuplot.Data(accuracy,title="Accuracy"),
129 Gnuplot.Data(precision,title="Precision"), 126 Gnuplot.Data(precision,title="Precision"),
130 Gnuplot.Data(recall,title="Recall"), 127 Gnuplot.Data(recall,title="Recall"),
131 Gnuplot.Data(f1,title="F1")) 128 Gnuplot.Data(f1,title="F1"))
132 g.hardcopy(recall_file+"-plot.ps", enhanced=1, color=1) 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 'strategy': params['strategy'], 133 'strategy': params['strategy'],
136 'accuracy': accuracy[20], 134 'accuracy': accuracy[20],
137 'precision': precision[20], 135 'precision': precision[20],