Skip to content

Commit

Permalink
plot results (recall and precision metrics)
Browse files Browse the repository at this point in the history
  • Loading branch information
yolanda93 committed May 28, 2016
1 parent c50fd65 commit c08bd87
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions ir_evaluator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import matplotlib.pyplot as plot
class IREvaluator(object):
"""description of class"""
#################################################################################
Expand All @@ -18,11 +19,8 @@ def __init__(self,relevance_docs,ranking_query):
query_id += 1
else:
print("\n-------------------------->Query = " + str(query_id) )
self.evaluate_query(ranking_query[0],relevants_docs_query,0)
self.evaluate_query(ranking_query[1],relevants_docs_query,1)





#################################################################################
## @brief evaluate_query
Expand All @@ -39,6 +37,8 @@ def evaluate_query(self,ranking,relevants_docs_query,query_id):

print(" Precision: " + str(precision) + "\n")
print(" Recall: " + str(recall) + "\n")

plot_results(recall, precision)

return

Expand Down Expand Up @@ -99,3 +99,27 @@ def get_precision(self,true_positives,false_positives):
relevant_items_retrieved=true_positives+false_positives
precision=float(true_positives)/float(relevant_items_retrieved)
return precision


#################################################################################
## @brief plot_results
# @details plot the result of evaluate each query
# @param recall retrieved documents correctly
# @param precision retrieved documents incorrectly
#################################################################################
def plot_results(recall, precision):
plot.plot(recalls, precisions)
plot.ylabel('precision')
plot.xlabel('recall')
plot.draw()

path_save = raw_input("Please, provide the path where the results should be saved \n")
if len(path_save) >0:
if os.path.exists(path_save):
plt.savefig(path_save)
else:
os.makedirs(path_save)

#show results
plot.show()
plot.close()

0 comments on commit c08bd87

Please sign in to comment.