ในการวาดเส้นโค้ง Precision-Recall ด้วย interpolation ใน Python สามารถทำตามขั้นตอนดังนี้:
ขั้นตอน
ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
สร้าง r, p และ duplicate recall, i data points ด้วย numpy
สร้าง figure และชุด subplots
วาด recall matrix ในช่วง r.shape
วาดข้อมูล r และ dup_r ด้วยเมธอด plot()
แสดงรูปด้วยเมธอด show()
ตัวอย่าง
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
r = np.linspace(0.0, 1.0, num=10)
p = np.random.rand(10) * (1. - r)
dup_p = p.copy()
i = r.shape[0] - 2
while i >= 0:
if p[i + 1] > p[i]:
p[i] = p[i + 1]
i = i - 1
fig, ax = plt.subplots()
for i in range(r.shape[0] - 1):
ax.plot((r[i], r[i]), (p[i], p[i + 1]), 'k-', label='', color='red')
ax.plot((r[i], r[i + 1]), (p[i + 1], p[i + 1]), 'k-', label='', color='red')
ax.plot(r, dup_p, 'k--', color='blue')
plt.show()
ผลลัพธ์
จะแสดงเส้นโค้ง Precision-Recall แบบ interpolated (สีแดง) และ original (สีน้ำเงิน 점선)
