计算点击数据中的准确率和召回率
Calculating Precision and Recall in Click Data
我正在尝试使用点击数据构建精确度和召回率图表。我有两个数据源。
- 第一个数据源根据给定 query_id.
所有用户单击 item_ids
- 第二个数据源具有给定 query_id 的所有相关 item_ids。
我用了python,把这两个数据源放到字典里,如下:
>>> print clicked_data
{101: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 103: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]}
>>> print all_relevant_data
{101: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], 103: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]}
我正在阅读 scikit-learn 网站 (http://scikit-learn.org/stable/auto_examples/plot_precision_recall.html) 中的文章并尝试遵循公式,但真的混淆了设置假阳性和假阴性。
遵循 scikit-learn 中的方程式:根据上面的示例预测项目 101
P = T_positive/ (T_positive + F_positive)
>>> float(len(clicked_data[101]))/float(len(all_relevant_data[101]))
0.5555555555555556
但是当我试图弄清楚 Recall 时,我在获取点击数据的假阴性项时遇到了问题。理论上 False Negative 意味着标记不正确。我所拥有的只是给定 ID 的用户点击数据以及与该 ID 相关的所有项目。
R = T_positive / (T_positive + F_negative)
如何才能正确计算精度和召回率,以便构建图表。
换句话说,如果这不是评估结果的好指标,考虑到我只有上述数据这一事实,什么才是好的指标?
只需点击 (TP) 和相关数据 (TP + FN),您就可以计算召回率 - 但不能计算精度。您没有告诉您 FP 值的数据集。
您可以根据您的数据集计算 precision@k、recall@k。但是您需要对文档进行排名才能计算它们。
数据集
一个众所周知的数据集是 AOL Search Query Logs,您可以使用它来构建基于检索的系统(您只需要一个数据集和一个检索函数)来计算精度、召回率、平均精度和平均精度。我简单解释一下上面提到的术语。
文档排名/检索功能
Okapi BM25(BM 代表最佳匹配)是搜索引擎用来根据匹配文档与给定搜索查询的相关性对匹配文档进行排名的排名函数。它基于概率检索框架。 BM25 是一个 bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document, regardless of the inter-relationship between the query terms within a document (e.g., their relative proximity). See the Wikipedia 页面以获取更多详细信息。
准确率和召回率
精准措施"of all the documents we retrieved as relevant how many are actually relevant?".
Precision = No. of relevant documents retrieved / No. of total documents retrieved
召回措施"Of all the actual relevant documents how many did we retrieve as relevant?".
Recall = No. of relevant documents retrieved / No. of total relevant documents
假设,当查询 "q" 被提交给具有 100 个相关文档 w.r.t 的信息检索系统(例如,搜索引擎)时。查询 "q",系统从 600 个文档中检索出 68 个文档。在检索到的 68 份文件中,有 40 份文件是相关的。所以,在这种情况下:
Precision = 40 / 68 = 58.8%
和 Recall = 40 / 100 = 40%
F-Score / F-measure 是精确率和召回率的加权调和平均值。传统的 F-measure 或平衡 F-score 是:
F-Score = 2 * Precision * Recall / Precision + Recall
平均精度
您可以这样想:您在 Google
中输入内容,它会显示 10 个结果。如果所有这些都是相关的,那可能是最好的。如果只有一些是相关的,比如其中五个,那么最好首先显示相关的。如果前五名无关紧要而好的只从第六名开始,那就太糟糕了,不是吗? AP 分数反映了这一点。
举个例子:
AvgPrec of the two rankings:
排名#1:(1.0 + 0.67 + 0.75 + 0.8 + 0.83 + 0.6) / 6 = 0.78
排名#2:(0.5 + 0.4 + 0.5 + 0.57 + 0.56 + 0.6) / 6 = 0.52
平均精度 (MAP)
MAP 是多个 queries/rankings 的平均精度的平均值。举例说明。
Mean average precision for the two queries:
对于查询 1,AvgPrec: (1.0+0.67+0.5+0.44+0.5) / 5 = 0.62
对于查询 2,AvgPrec: (0.5+0.4+0.43) / 3 = 0.44
所以,MAP = (0.62 + 0.44) / 2 = 0.53
有时,人们使用 precision@k
、recall@k
作为检索系统的性能衡量标准。您应该为此类测试构建一个检索系统。如果你想在 Java 中编写你的程序,你应该考虑 Apache Lucene 来构建你的索引。
我正在尝试使用点击数据构建精确度和召回率图表。我有两个数据源。
- 第一个数据源根据给定 query_id. 所有用户单击 item_ids
- 第二个数据源具有给定 query_id 的所有相关 item_ids。
我用了python,把这两个数据源放到字典里,如下:
>>> print clicked_data
{101: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 103: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]}
>>> print all_relevant_data
{101: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], 103: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]}
我正在阅读 scikit-learn 网站 (http://scikit-learn.org/stable/auto_examples/plot_precision_recall.html) 中的文章并尝试遵循公式,但真的混淆了设置假阳性和假阴性。
遵循 scikit-learn 中的方程式:根据上面的示例预测项目 101
P = T_positive/ (T_positive + F_positive)
>>> float(len(clicked_data[101]))/float(len(all_relevant_data[101]))
0.5555555555555556
但是当我试图弄清楚 Recall 时,我在获取点击数据的假阴性项时遇到了问题。理论上 False Negative 意味着标记不正确。我所拥有的只是给定 ID 的用户点击数据以及与该 ID 相关的所有项目。
R = T_positive / (T_positive + F_negative)
如何才能正确计算精度和召回率,以便构建图表。
换句话说,如果这不是评估结果的好指标,考虑到我只有上述数据这一事实,什么才是好的指标?
只需点击 (TP) 和相关数据 (TP + FN),您就可以计算召回率 - 但不能计算精度。您没有告诉您 FP 值的数据集。
您可以根据您的数据集计算 precision@k、recall@k。但是您需要对文档进行排名才能计算它们。
数据集
一个众所周知的数据集是 AOL Search Query Logs,您可以使用它来构建基于检索的系统(您只需要一个数据集和一个检索函数)来计算精度、召回率、平均精度和平均精度。我简单解释一下上面提到的术语。
文档排名/检索功能
Okapi BM25(BM 代表最佳匹配)是搜索引擎用来根据匹配文档与给定搜索查询的相关性对匹配文档进行排名的排名函数。它基于概率检索框架。 BM25 是一个 bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document, regardless of the inter-relationship between the query terms within a document (e.g., their relative proximity). See the Wikipedia 页面以获取更多详细信息。
准确率和召回率
精准措施"of all the documents we retrieved as relevant how many are actually relevant?".
Precision = No. of relevant documents retrieved / No. of total documents retrieved
召回措施"Of all the actual relevant documents how many did we retrieve as relevant?".
Recall = No. of relevant documents retrieved / No. of total relevant documents
假设,当查询 "q" 被提交给具有 100 个相关文档 w.r.t 的信息检索系统(例如,搜索引擎)时。查询 "q",系统从 600 个文档中检索出 68 个文档。在检索到的 68 份文件中,有 40 份文件是相关的。所以,在这种情况下:
Precision = 40 / 68 = 58.8%
和 Recall = 40 / 100 = 40%
F-Score / F-measure 是精确率和召回率的加权调和平均值。传统的 F-measure 或平衡 F-score 是:
F-Score = 2 * Precision * Recall / Precision + Recall
平均精度
您可以这样想:您在 Google
中输入内容,它会显示 10 个结果。如果所有这些都是相关的,那可能是最好的。如果只有一些是相关的,比如其中五个,那么最好首先显示相关的。如果前五名无关紧要而好的只从第六名开始,那就太糟糕了,不是吗? AP 分数反映了这一点。
举个例子:
AvgPrec of the two rankings:
排名#1:(1.0 + 0.67 + 0.75 + 0.8 + 0.83 + 0.6) / 6 = 0.78
排名#2:(0.5 + 0.4 + 0.5 + 0.57 + 0.56 + 0.6) / 6 = 0.52
平均精度 (MAP)
MAP 是多个 queries/rankings 的平均精度的平均值。举例说明。
Mean average precision for the two queries:
对于查询 1,AvgPrec: (1.0+0.67+0.5+0.44+0.5) / 5 = 0.62
对于查询 2,AvgPrec: (0.5+0.4+0.43) / 3 = 0.44
所以,MAP = (0.62 + 0.44) / 2 = 0.53
有时,人们使用 precision@k
、recall@k
作为检索系统的性能衡量标准。您应该为此类测试构建一个检索系统。如果你想在 Java 中编写你的程序,你应该考虑 Apache Lucene 来构建你的索引。