作业1:
我们假设文档数据库包含10个文档。对于给定的查询Q,以下文档是相关的:1、2、4、6、8、9。三个搜索系统为查询Q返回如下排列的结果列表:
S1: 1,4,5,6,9,10
S2: 2 3 5 6 7 10
S3: 1, 3, 4, 5, 6, 8
a)计算每个系统的精度/召回率曲线(用数值做一个表格,在一个图形上画出三个图形)
先求出对应的各个recall和precision
import numpy as np
import matplotlib.pyplot as plt
# 第二次作业
fig, ax = plt.subplots(figsize=(8, 4))
Recall = np.array([1 / 6, 1 / 3, 1 / 3, 3 / 6, 4 / 6, 4 / 6])
Precison = np.array([1 / 1, 1 / 1, 2 / 3, 3 / 4, 4 / 5, 4 / 6])
Recall1 = np.array([1 / 6, 1 / 6, 1 / 6, 2 / 6, 2 / 6, 2 / 6])
Precison1 = np.array([1 / 1, 1 / 2, 1 / 3, 2 / 4, 2 / 5, 2 / 6])
Recall2 = np.array([1 / 6, 1 / 6, 2 / 6, 2 / 6, 3 / 6, 4 / 6])
Precison2 = np.array([1 / 1, 1 / 2, 2 / 3, 2 / 4, 3 / 5, 4 / 6])
ax.plot(Recall, Precison, color='#7B68EE', linestyle='--', marker='o', linewidth=1, label='S1')
ax.plot(Recall1, Precison1, color='#40E0D0', linestyle='--', marker='o', linewidth=1, label='S2')
ax.plot(Recall2, Precison2, color='#F4A460', linestyle='--', marker='o', linewidth=1, label='S3')
ax.grid()
ax.set_xticks(np.arange(0, 1.1, 0.1))
ax.set_xlabel("Recall")
ax.set_yticks(np.arange(0, 1.1, 0.1))
ax.set_ylabel("Precison")
ax.legend()
plt.show()