python - 在 python 中向预测值添加误差线

标签 python matplotlib

我运行了 lstm 模型 10 次,并对这些值进行平均以获得平均值,这就是我的预测值。我计算了每行的标准偏差并将其添加到包含我的预测值的数据帧(test_iterations)中。我现在想绘制误差线,以便我的图表看起来像这样(在 Excel 中完成)enter image description here

但是当我使用以下代码时,我得到一个如下所示的图表

plt.errorbar(test_iterations['Mean'].values, 
                     test_iterations['Mean'].values,
                     yerr = test_iterations['Stdv'].values,
                     fmt='-o')

enter image description here

我不确定我所做的是否正确,因为我在同一件事的代码上添加了 x 和 y 值,但不确定要添加什么

最佳答案

plt.errorbar() 的第一个参数是要绘制的点的 x 坐标。在您的情况下,它是值的排名。

试试这个:

import numpy as np

plt.errorbar(np.arange(len(test_iterations['Mean'])),
             test_iterations['Mean'].values,
             yerr=test_iterations['Stdv'].values,
             fmt='-o')

关于python - 在 python 中向预测值添加误差线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63933395/

相关文章:

python - matplotlib "fail to allocate bitmap"经过一些迭代

python - python生成器函数不支持的朴素排列算法

python - 堆排序Python实现

python - 高斯过程算法出错,numpy 内存问题?

python - 将 numpy 数组保存到 txt

python - 使用 Seaborn 将一维时间序列绘制为一条线,并沿 y 轴绘制边缘直方图

python - python 2、matplotlib 1.1.1 中的 pylab.ion() 以及在程序运行时更新绘图

python - 如何使用 matplotlib 循环绘制图像列表?

python - h5py 中的组是否保留其成员添加的顺序?

python - 在 matplotlib 中确定按钮单击的子图