本文整理汇总了Python中query.Query.keys方法的典型用法代码示例。如果您正苦于以下问题:Python Query.keys方法的具体用法?Python Query.keys怎么用?Python Query.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query.Query
的用法示例。
在下文中一共展示了Query.keys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_rel_prob
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import keys [as 别名]
def plot_rel_prob(self, query_length, x_func, _method, plot_ratio=True,
plot_total_or_avg=True, plot_rel_or_all=True,
performance_as_legend=True, drawline=True, numbins=60, xlimit=0,
ylimit=0, zoom_x=0, compact_x=False, curve_fitting=False,
draw_individual=False, draw_all=True, oformat='eps'):
"""
plot the P(D=1|TF=x)
Input:
@query_length: only plot the queries of length, 0 for all queries.
@x_func: how to get the x-axis of the figure. By default, this should
be TF values. But we are flexible with other options, e.g. tf/dl
@_method: Which method is going to be plot. The parameters should also be
attached, e.g. dir,mu:2500
@plot_ratio: When this is false, plot the y-axis as the number of relevant
documents; When this is true, plot the y-axis as the #rel_docs/#docs
@plot_total_or_avg: When this is true, plot the y-axis as the collection
total ; When this is false, plot the collection average.
Only available when plot_ratio is false is only available for collection-wise
@plot_rel_or_all: When this is true, plot the y-axis as the number of
relevant docs ; When this is false, plot the number of all docs.
Only available when plot_ratio is false is only available for collection-wise
@performance_as_legend: whether to add performance(e.g. MAP)
as part of the legend
@drawline: draw the data points as line(true) or dots(false)
@numbins: the number of bins if we choose to plot x points as bins, 0 for no bins
@xlimit: the limit of xaxis, any value larger than this value would not
be plotted. default 0, meaning plot all data.
@ylimit: the limit of yaxis, any value larger than this value would not
be plotted. default 0, meaning plot all data.
@zoom: whether zoom part of the plot
@zoom_x: the zoom start x point, 0 for no zoom.
@compact_x: map the x to continuous integers, e.g. 1,2,3,4,....
@oformat: output format, eps or png
"""
collection_name = self.collection_name
cs = CollectionStats(self.collection_path)
doc_details = GenDocDetails(self.collection_path)
output_root = os.path.join('collection_figures', str(query_length))
if not os.path.exists(os.path.join(self.all_results_root, output_root)):
os.makedirs(os.path.join(self.all_results_root, output_root))
if query_length == 0:
queries = Query(self.collection_path).get_queries()
else:
queries = Query(self.collection_path).get_queries_of_length(query_length)
queries = {ele['num']:ele['title'] for ele in queries}
#print qids
rel_docs = Judgment(self.collection_path).get_relevant_docs_of_some_queries(queries.keys(), 1, 'dict')
#print np.mean([len(rel_docs[qid]) for qid in rel_docs])
eval_class = Evaluation(self.collection_path)
print _method
p = eval_class.get_all_performance_of_some_queries(
method=_method,
qids=queries.keys(),
return_all_metrics=False,
metrics=['map']
)
collection_x_dict = {}
collection_level_maxX = 0.0
num_cols = min(4, len(queries))
num_rows = int(math.ceil(len(rel_docs)*1.0/num_cols))
fig, axs = plt.subplots(nrows=num_rows, ncols=num_cols, sharex=False, sharey=False, figsize=(2*num_cols, 2*num_rows))
font = {'size' : 5}
plt.rc('font', **font)
row_idx = 0
col_idx = 0
#idfs = [(qid, math.log(cs.get_term_IDF1(queries[qid]))) for qid in rel_docs]
#idfs.sort(key=itemgetter(1))
all_expected_maps = []
if curve_fitting:
all_fitting_results = [{'sr': [], 'ap':[], 'ap_diff':[]} for i in range(FittingModels().size())]
all_fitting_performances = {}
for qid in sorted(queries):
if num_rows > 1:
ax = axs[row_idx][col_idx]
else:
if num_cols > 1:
ax = axs[col_idx]
else:
ax = axs
col_idx += 1
if col_idx >= num_cols:
row_idx += 1
col_idx = 0
query_term = queries[qid]
maxTF = cs.get_term_maxTF(query_term)
#idf = math.log(cs.get_term_IDF1(query_term))
#legend = 'idf:%.2f'%idf
if performance_as_legend:
legend = '\nAP:%.4f' % (p[qid]['map'] if p[qid] else 0)
x_dict = {}
qid_docs_len = 0
#for row in cs.get_qid_details(qid):
for row in doc_details.get_qid_details(qid):
qid_docs_len += 1
x = x_func(cs, row)
if x > collection_level_maxX:
collection_level_maxX = x
rel = (int(row['rel_score'])>=1)
if x not in x_dict:
#.........这里部分代码省略.........