print "Running trec_eval script..."
N = len(y_pred_test)
df_submission = pd.DataFrame(index=numpy.arange(N), columns=['qid', 'iter', 'docno', 'rank', 'sim', 'run_id'])
df_submission['qid'] = qids_test
df_submission['iter'] = 0
df_submission['docno'] = numpy.arange(N)
df_submission['rank'] = 0
df_submission['sim'] = y_pred_test
df_submission['run_id'] = 'nnet'
df_submission.to_csv(os.path.join(output_dir, 'submission.txt'), header=False, index=False, sep=' ')
df_gold = pd.DataFrame(index=numpy.arange(N), columns=['qid', 'iter', 'docno', 'rel'])
df_gold['qid'] = qids_test
df_gold['iter'] = 0
df_gold['docno'] = numpy.arange(N)
df_gold['rel'] = y_test
df_gold.to_csv(os.path.join(output_dir, 'gold.txt'), header=False, index=False, sep=' ')
subprocess.call("/bin/sh run_eval.sh '{}'".format(output_dir), shell=True)
我在tensorflow中有这个代码并且它已成功编译。 submission.txt中的数据如下:(以qid为33.1为例)
33.1 0 12 0 0.27250546217 nnet
33.1 0 13 0 0.262122750282 nnet
33.1 0 14 0 0.292897969484 nnet
33.1 0 15 0 0.244421452284 nnet
33.1 0 16 0 0.00145227077883 nnet
33.1 0 17 0 0.264055848122 nnet
33.1 0 18 0 0.235591337085 nnet
gold.txt中的数据如下所示:(例如,将qid视为33.1)
33.1 0 12 1
33.1 0 13 1
33.1 0 14 1
33.1 0 15 1
33.1 0 16 0
33.1 0 17 0
33.1 0 18 0
我认为MAP结果应该像这样计算: 首先,按分数(即“sim”)及其标签对预测进行排序。 所以排序后的输出应该是:(只保留小数点后2-3位数,以便清除,模式以{score,label}风格给出)
0.29 1
0.27 1
0.264 0
0.262 1
0.24 1
0.23 0
0.00 0
所以我认为MAP应该是:(1/1 + 2/2 + 3/4 + 4/5)/ 5 = 0.71
但是在submission.txt.treceval中,它说 0.8875 ,我不知道它是怎么回事。