如何在 Python Matplotlib 中借助插值来绘制定精度召回曲线?


要在 Python 中借助插值绘制定精度召回曲线,我们可以执行以下步骤:

步骤

  • 设置图形大小并调整子图之间和周围的填充。

  • 使用 numpy 创建 rp 和重复的召回,即数据点。

  • 创建一个图形和一组子图。

  • 绘制取值范围在 r.shape 中的召回矩阵。

  • 使用 plot() 方法绘制 r 和 dup_r 数据点。

  • 要显示图形,请使用 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()

输出

它将生成以下输出:

更新于:2022 年 2 月 2 日

782 人浏览

开启您的职业生涯

完成课程以获得认证

开始学习
广告
© . All rights reserved.